如何使用CodeIgniter将水印添加到S3存储桶中存储的图像中?

时间:2019-04-03 04:55:37

标签: php codeigniter amazon-s3 watermark bucket

我不想将图像下载到本地,我想在图像中添加徽标作为水印,即将图像存储在S3存储桶中。

我不想在本地系统中执行此水印处理,我不知道该怎么做。这是我在CodeIgniter中的代码

public function GetRendomImgForMaxico()
    {
        /* S3 server :- get 5 order and one image from each orders */
         $getRendomLatestOrder = $this->db->query("select invoice from ord_order
            left join users
            on users.id = ord_order.userId and users.region_id < 36
            where ord_order.payment_status = 'P' AND ord_order.num_day_shoots > 0
            order by ord_order.id desc limit 5");
        $latestImgs = $getRendomLatestOrder->result_array();

        $this->load->library('aws_sdk');
        foreach ($latestImgs as $latestImg) {
            $response = $this->aws_sdk->listObjects(
                array(
                    'Bucket' => $this->bucket_name, 
                    'MaxKeys' => 1000, 
                    'Prefix' => $this->order_directory.'ORD_'.$latestImg['invoice'].'/MLS/'
                )
            );
            $image = $response->getPath('Contents');
            $images[] = end($image);
        }
        $urls = array_column($images, 'Key');
        foreach($urls as $key=>$url) {
            $urls[$key] = 'https://s3.amazonaws.com/BUCKETNAME/'.$url;
            $result = $this->aws_sdk->copyObject([
                'Bucket' => $this->config->item('bucketname'),
                'CopySource' => "/".$this->config->item('bucketname')."/".$url,
                'Key' => 'recent_shoots/'.$url,
                'ACL' => 'public-read']
            )->toArray();

            /** Watermark add from here */
            $masterURL = 'https://s3.amazonaws.com/BUCKETNAME/recent_shoots/'.$url;
            $path='https://s3.amazonaws.com/BUCKETNAME/recent_shoots/logo/logo.png';
            $this->load->library('image_lib');              
            $config1['image_library'] = 'gd2'; 
            $config1['source_image']     = $masterURL;
            $config1['wm_type']          = 'overlay';
            $config1['wm_overlay_path']  = $path; 
            $config1['wm_opacity']       = 100;
            $config1['wm_vrt_alignment'] = 'top';
            $config1['wm_hor_alignment'] = 'right';
            $this->image_lib->initialize($config1);
            $this->image_lib->watermark();
            die();
        }
    }

0 个答案:

没有答案