I'm looking for PHP class (solution) for generating image thumbnails with watermarks on the fly. Any idea ?
+2
A:
Full tutorial here : http://articles.sitepoint.com/article/watermark-images-php
Thank you Google...
Kaaviar
2010-07-27 11:25:46
A:
You can do this using using the imagecopyresampled()
function. Heres a easy and clear tutorial of adding watermark to thumbnails . Also you can use imagettftext()
function to use fonts as your watermark
Tutorial Link: http://www.phpjabbers.com/phpexample.php?eid=20
Aakash Chakravarthy
2010-07-27 11:27:17
A:
I've successfully used this code to add text to an (thumbnail) image:
(note that you'll need to provide a font)
function createImage($in_filename, $out_filename, $width, $height)
{
$src_img = ImageCreateFromJpeg($in_filename);
$old_x = ImageSX($src_img);
$old_y = ImageSY($src_img);
$dst_img = ImageCreateTrueColor($width, $height);
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y);
addWatermark($dst_img);
ImageJpeg($dst_img, $out_filename, 80);
ImageDestroy($dst_img);
ImageDestroy($src_img);
}
function addWatermark($image)
{
$text = "watermark text";
$font = realpath($_SERVER["DOCUMENT_ROOT"] . "/code/COURBD.TTF"); // case sensitive
if ($font == false) return;
$fontSize = 11;
$borderOffset = 4;
$dimensions = ImageTtfBBox($fontSize, 0, $font, $text . "@");
$lineWidth = ($dimensions[2] - $dimensions[0]);
$textX = (ImageSx($image) - $lineWidth) / 2;
$textY = $borderOffset - $dimensions[7];
$white = ImageColorAllocate($image, 240, 240, 240);
ImageTtfText($image, $fontSize, 0, $textX, $textY, $white, $font, $text);
}
Feedback welcome.
gt
2010-07-27 11:43:11