From 3979ea2bbe19b5f4666736901dcc918b259c33d3 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 3 Oct 2009 16:08:51 +0000 Subject: better GD watermarking --- lib/watermark.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/watermark.php b/lib/watermark.php index 13eb598a0..e28194b18 100644 --- a/lib/watermark.php +++ b/lib/watermark.php @@ -27,27 +27,31 @@ function tp_gd_watermark($image) { if (!$watermark_text) return; - + global $CONFIG; + $owner = get_loggedin_user(); $watermark_text = tp_process_watermark_text($watermark_text, $owner); + + // transparent gray + imagealphablending($image, true); + $textcolor = imagecolorallocatealpha($image, 50, 50, 50, 60); + // font and location + $font = $CONFIG->pluginspath . "tidypics/fonts/LiberationSerif-Regular.ttf"; + $bbox = imagettfbbox(20, 0, $font, $watermark_text); + $text_width = $bbox[2] - $bbox[0]; + $text_height = $bbox[1] - $bbox[7]; - $font = 5; - $line_width = strlen($watermark_text) * imagefontwidth($font); - $line_height = imagefontheight($font); - - $image_width = 600; - $image_height = 450; + $image_width = imagesx($image); + $image_height = imagesy($image); - // matching -gravity south -geometry +0+10 - $top = $image_height - $line_height - 10; - $left = round(($image_width - $line_width) / 2); + $left = $image_width / 2 - $text_width / 2; + $top = $image_height - 20; - imagealphablending($image, true); - $textcolor = imagecolorallocatealpha($image, 50, 50, 50, 50); - imagestring($image, $font, $left, $top, $watermark_text, $textcolor); + // write the text on the image + imagettftext($image, 20, 0, $left, $top, $textcolor, $font, $watermark_text); } function tp_imagick_watermark($filename) { -- cgit v1.2.3