PHP Image Watermarking
I had to build this for a client rather swiftly but here is the brass tax of the matter. My client requested that every image in a section would be automatically water marked. I read a few good articles and played around a bit before creating this based on the others I had been reading about.
Criteria:
- Auto centered mark
- semi transparency
- works with 24-bit .png files for image watermark
- Must work on the fly
- must be able to watermark png/jpeg file types
- due Monday by noon
That being said I produced the following based on notes I took from various sites:
<?php
// example url
watermark.php?i=display.php?show=23
$imageUrl = $_GET['i'];
$watermarkUrl = “watermark.png”;
$orgimage=imagecreatefromjpeg(”{$imageUrl}”);
$watermark=imagecreatefrompng(”{$watermarkUrl}”);
$watermarkDetails=getimagesize(”{$watermarkUrl}”);
$imageDetails = getimagesize(”{$imageUrl}”);
$centerx = (($imageDetails[0] - $watermarkDetails[0])/2);
$centery = (($imageDetails[1] - $watermarkDetails[1])/2);
imagecopy($orgimage,$watermark,$centerx,$centery,0,0,
imagesx($watermark),imagesy($watermark));
header(”Content-Type: image/jpeg”);
imagejpeg($orgimage);
imagedestroy($watermark);
imagedestroy($orgimage);
exit;
?>
Monday, January 28th, 2008 at 6:02 pm and is filed under php, work. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.