I wrote a small article that and I though it will be nice to share with you
Do you have an image that you want to keep a copyright on? Putting you logo or a URL of your website on each and every image is a quite a long and tedious process so here is a solution in PHP that will help you make things easier and neater.
Using this script one can specify two images: the image to be watermarked and the watermark itself. If you have several images do not waste time putting your watermark on each and every image. Just use this script and all your images are watermarked
PHP Code:
<?php
header('content-type: image/jpeg'); //tells the webserver that the output will be an image
$_image = "snippetcollection.jpg"'; $watermark = 'watermark.png';
$watermark = imagecreatefrompng($watermark); //gets the watermark
//gets the dimensions of the watermark
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
//gets the image to put the watermark on and related information about it
$image = imagecreatefromjpeg($_image);
$size = getimagesize($_image);
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>
If you would like more interesting snippets and examples in PHP visit Snippet Collection. There you can find a large number of snippets in various languages such as PHP, Javascript and other languages.
Note this script is inspired by a sitepoint article.
Last edited by bambolin; 09-23-2005 at 05:14 AM..
|