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);
}
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);
}