PDA

View Full Version : Integration of a script to create a watermark with GD2


TomKa
16th of March 2004 (Tue), 08:27
Is it possible to include a function to add a watermark with GD2 if there is no ImageMagick installed on the webserver?

After searching a bit on the net I have found this script. It can be executed in the image directoy, maybe it's also possible to include it into the resize function for GD (since I'm not a php geek) ?

Description: http://www.phpgeek.com/articles.php?content_id=6
Download: http://www.phpgeek.com/files/watermark.zip


<?php
$watermark = "proof150.png";
$quality = "75";
$imagedir = "images";

$workingdir = opendir ($imagedir);
while ($entry = readdir($workingdir)) {
if(eregi(".+\.jpe?g$", $entry )) {
$i=1;
watermark($imagedir."/".$entry, $entry, $watermark, $quality);
$i++;
}
}

//$filename should be a JPG and $watermark a PNG-24 with alpha transparency. $quality is 1-100 JPG quality on output.
function watermark($srcfilename, $newname, $watermark, $quality) {
$imageInfo = getimagesize($srcfilename);
$width = $imageInfo[0];
$height = $imageInfo[1];
$logoinfo = getimagesize($watermark);
$logowidth = $logoinfo[0];
$logoheight = $logoinfo[1];
$horizextra =$width - $logowidth;
$vertextra =$height - $logoheight;
$horizmargin = round($horizextra / 2);
$vertmargin = round($vertextra / 2);
$photoImage = ImageCreateFromJPEG($srcfilename);
ImageAlphaBlending($photoImage, true);
$logoImage = ImageCreateFromPNG($watermark);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);
//ImageJPEG($photoImage); // output to browser
ImageJPEG($photoImage,"images/watermarked/wm_".$newname, $quality);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}

wkitty42
29th of March 2004 (Mon), 00:36
Is it possible to include a function to add a watermark with GD2 if there is no ImageMagick installed on the webserver?
oh man! yes... that's cool! i have this very problem of no imagemagick available on my platform... this would be a huge help and really take away a lot of manual labor i'm currently doing...

After searching a bit on the net I have found this script. It can be executed in the image directoy, maybe it's also possible to include it into the resize function for GD (since I'm not a php geek) ?

Description: http://www.phpgeek.com/articles.php?content_id=6
Download: http://www.phpgeek.com/files/watermark.zip
excellent... i don't quite understand it either but i'm sure it can be fitted into EE... pekka? are you with us? ;)

Pekka
29th of March 2004 (Mon), 12:39
Yes, this (or some other code) will be added in next version (1.51 or so) along with preview like ImageMagick now has.