Lab #5

8. Write a PHP script to create watermarks using Imagecopymerge

index.php

First, you need two photos. Add two photos where this program or script is located or just paste the image location path in $source_image and $dest_image variable. Now try this code.

<?php
$source_image = 'logo.jpg';
$dest_image = 'tree.jpg';

list($srcWidth, $srcHeight) = getimagesize($source_image);
$src = imagecreatefromjpeg($source_image);
$dest = imagecreatefromjpeg($dest_image);

imagecolortransparent($src,imagecolorat($src,0,0));
imagecopymerge($dest,$src,10,10,0,0,$srcWidth,$srcHeight,50);
imagejpeg($dest,'output.jpg',100);
imagedestroy($src);
imagedestroy($dest);
?>

Output

Now open this page in the browser and image output saved where your program is located or located at where you define the path. Image saved as ouput.jpg (according to above code)

Output image looks like the following. Two images were merged.


Happy Coding :)