Watermark upload image in codeigniter

0

Hello! I'm trying to insert a watermark when registering the image, but the image is up, but it does not insert the watermark or return errors, does anyone have any suggestions?

Follow the code below:

foreach ($_FILES as $field => $file) {
        if ($file['error'] == 0) {
            if ($this->upload->do_upload($field)) {
                $data = $this->upload->data();
                $dados['imagem'] = $data['file_name'];       

                $img_config['wm_type'] = 'overlay';
                $img_config['wm_overlay_path'] = PATH_FRONT_END_UPLOAD.'usuarios/logo.png';
                $img_config['wm_x_transp'] = 20;
                $img_config['wm_y_transp'] = 10;
                $img_config['wm_opacity'] = 50;
                $img_config['wm_vrt_alignment'] = 'bottom';
                $img_config['wm_hor_alignment'] = 'center';
                $config['source_image'] = $data['full_path'];  
                $this->image_lib->watermark();
                $this->image_lib->clear();
                $this->image_lib->initialize($config); 
            } else {
                $errors = $this->upload->display_errors();
                die($errors);
            }
        }
    }
    
asked by anonymous 25.02.2016 / 20:55

1 answer

2

Good afternoon. I had a problem similar to generating thumbnails. The solution was to load the lib out of foreach and with each new configuration parameterized, I used the following code:

$this->image_lib->clear();
$this->image_lib->initialize($config);

I hope I have helped!

Oss

Updated: Please try the following code:

foreach ($_FILES as $field => $file) {
        if ($file['error'] == 0) {
            if ($this->upload->do_upload($field)) {
                $data = $this->upload->data();
                $dados['imagem'] = $data['file_name'];       

                $img_config['wm_type'] = 'overlay';
                $img_config['wm_overlay_path'] = PATH_FRONT_END_UPLOAD.'usuarios/logo.png';
                $img_config['wm_x_transp'] = 20;
                $img_config['wm_y_transp'] = 10;
                $img_config['wm_opacity'] = 50;
                $img_config['wm_vrt_alignment'] = 'bottom';
                $img_config['wm_hor_alignment'] = 'center';
                $config['source_image'] = $data['full_path'];  
                $this->image_lib->clear();
                $this->image_lib->initialize($img_config);                 
                $this->image_lib->watermark();

            } else {
                $errors = $this->upload->display_errors();
                die($errors);
            }
        }
    }
    
26.02.2016 / 18:31