Watermark image upload in codeigniter

Asked

Viewed 287 times

0

Hello! I’m trying to insert watermark when registering the image, but the image is upada, only it does not insert the watermark and does not return errors, someone has some suggestion?

Follows 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);
            }
        }
    }

1 answer

2


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

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

I hope I’ve helped!

Oss

Updated: 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);
            }
        }
    }
  • Hello! I tried to insert the libs before the foreach, but it also didn’t work :( updated the code and removed the code to insert Thumbs, because I don’t need Thumbs at the moment, so the code is much smaller and easier to understand.

  • Updated, try the code I refactored from your... Oss

Browser other questions tagged

You are not signed in. Login or sign up in order to post.