CodeIgniter Forums

Full Version: Image watermarking with image overlay support
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Currently there is no support for image watermarking with image overlay in image manipulation class. Text overlay is not enough to cover most of the image watermarking needs.
CI has not special methods for working with watermark  "on the box". But i created self library which works with images and also can create watermarks. For example this is bit of code of a library method for creating watermarks. You can use this code on your project.
PHP Code:
public function watermarkImagestring $file, array $config = [])
        if ($this->_checkFileExists($filefalse) && !empty($config))
            if ($this->_checkFileExists($config['wm_image'], false))
                $file FCPATH $file;

                $fileType pathinfo($file,PATHINFO_EXTENSION);

                    case 'png':

                        $img imagecreatefrompng($file);


                    case 'jpg':
                    case 'jpeg':

                        $img imagecreatefromjpeg($file);


                $watermark imagecreatefrompng($config['wm_image']);



                $img_w imagesx($img);

                $img_h imagesy($img);

                $wtrmrk_w imagesx($watermark);

                $wtrmrk_h imagesy($watermark);

                $dst_x = ($img_w 2) - ($wtrmrk_w 2); // For centering the watermark on any image

                $dst_y = ($img_h 2) - ($wtrmrk_h 2); // For centering the watermark on any image


                imagejpeg($img$file$config['wm_quality'] ?? 90);