Basically, I have 2 php script. 1 of the php scripts is to display and the other 1 is the watermark function.
I use this PHP to display the image with watermark:
<img src="watermark1.php?image=photo.jpg>
This is my watermark1.php:
<?php
// this tells the browser to render jpg image
header('content-type: image/jpeg');
// getting the image name from GET variable
$image = $_GET['image'];
// creating png image of watermark
$watermark = imagecreatefrompng('watermark.png');
// getting dimensions of watermark image
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
// creating jpg from original image
$image_path = $image;
$image = imagecreatefromjpeg($image_path);
//something went wrong
if ($image === false) {
return false;
}
// getting the dimensions of original image
$size = getimagesize($image_path);
// placing the watermark 5px from bottom and right
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
// blending the images together
imagealphablending($image, true);
imagealphablending($watermark, true);
// creating the new image
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagejpeg($image);
// destroying and freeing memory
imagedestroy($image);
imagedestroy($watermark);
?>
However, the watermarked image could not be displayed. I heard about GDLibrary and ImageMagicK but i have no idea what are these 2 about. Is there a way to add watermark just by adding php codes or is it a must to import the GDLibrary/ImageMagicK.
Thanks for taking your time.