watermark text on image php code example

Example: watermark image php

$targetFilePath='assets/images/targetimage.php';
            file_put_contents($targetFilePath,$decoded);
            
            $watermarkImagePath = 'assets/images/watermark/watermark.png'; 
            $watermarkImg = imagecreatefrompng($watermarkImagePath); 
            $im = imagecreatefrompng($targetFilePath); 
            
            // Set the margins for the watermark 
            $marge_right = 20; 
            $marge_bottom = 20; 
             
            // Get the height/width of the watermark image 
            $sx = imagesx($watermarkImg); 
            $sy = imagesy($watermarkImg); 
             
            // Copy the watermark image onto our photo using the margin offsets and  
            // the photo width to calculate the positioning of the watermark. 
            imagecopy($im, $watermarkImg, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($watermarkImg), imagesy($watermarkImg)); 
             
            // Save image and free memory 
            imagepng($im, $targetFilePath); 
            imagedestroy($im);

Tags:

Php Example