CodeIgniter Forums
Image watermarking with image overlay support - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forum-29.html)
+--- Thread: Image watermarking with image overlay support (/thread-79436.html)



Image watermarking with image overlay support - MrWhite - 06-15-2021

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.


RE: Image watermarking with image overlay support - Avega Soft - 07-06-2021

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

                switch($fileType)
                {
                    case 'png':

                        $img imagecreatefrompng($file);

                        break;

                    case 'jpg':
                    case 'jpeg':
                    default:

                        $img imagecreatefromjpeg($file);

                        break;
                }

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

                imagealphablending($watermarkfalse);

                imagesavealpha($watermarktrue);

                $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

                imagecopy($img$watermark$dst_x$dst_y00$wtrmrk_w$wtrmrk_h);

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

                imagedestroy($img);

                imagedestroy($watermark);
            }
        }