List of things needed:
1. your image in any format
2. watermark image--in gif format with transparent background
3. script below with name (i.e. watermark.php)
<?php
// this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
// where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
// where this script is named watermark.php
// call this script with an image tag
// <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
$imagesource = $_GET['path'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
if (!$image) die();
$watermark = @imagecreatefromgif('watermark.gif');
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2);
$startheight = (($imageheight - $watermarkheight)/2);
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>
Name this script, i.e. watermark.php and call this script as following:
<img src="watermark.php?path=image_name.filetype">the only thing you need to chage is "image_name.filetype" and of course you can have the relative path such as:
<img src="folder/watermark.php?path=folder/imagename">
The caution here is the script watermark.php and watermark.gif should be in the same location. watermark.gif should have transparent background.
As you can read it from the site, the location where the watermark.gif appears can be modified by adjusting this line of the code:
$startwidth = (($imagewidth - $watermarkwidth)/2); $startheight = (($imageheight - $watermarkheight)/2);To have it appear on the bottom right corner, try this:
$startwidth = (($imagewidth - $watermarkwidth) ); $startheight = (($imageheight - $watermarkheight) );
Personal note: I have installed Apache2 and PHP5 in my computer and couldn't get this working at first. Later I found out I had to edit php.ini under extension to enable php_gd2.dll in order to make it work under http://localhost/
I hope you find a good usage out of this














