diff options
author | Cash Costello <cash.costello@gmail.com> | 2009-10-03 16:08:51 +0000 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2009-10-03 16:08:51 +0000 |
commit | 3979ea2bbe19b5f4666736901dcc918b259c33d3 (patch) | |
tree | 6a60938e66059c30cf263e2b2346dad262040769 /lib/watermark.php | |
parent | e1652f241d7ef5e4641af27fae22240232787568 (diff) | |
download | elgg-3979ea2bbe19b5f4666736901dcc918b259c33d3.tar.gz elgg-3979ea2bbe19b5f4666736901dcc918b259c33d3.tar.bz2 |
better GD watermarking
Diffstat (limited to 'lib/watermark.php')
-rw-r--r-- | lib/watermark.php | 30 |
1 files changed, 17 insertions, 13 deletions
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) { |