diff options
author | Cash Costello <cash.costello@gmail.com> | 2009-09-13 23:56:59 +0000 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2009-09-13 23:56:59 +0000 |
commit | 6b156c9e10c6b832c8ab4c21edf6eac5ea301b98 (patch) | |
tree | 670b4c9e2035de5173bae7fab0baf4b6f4464eb0 /lib/watermark.php | |
parent | 35175e8b885c00f2120d19d89b8177c384db68d8 (diff) | |
download | elgg-6b156c9e10c6b832c8ab4c21edf6eac5ea301b98.tar.gz elgg-6b156c9e10c6b832c8ab4c21edf6eac5ea301b98.tar.bz2 |
tweaked GD watermarking and added a better imagick watermarking
Diffstat (limited to 'lib/watermark.php')
-rw-r--r-- | lib/watermark.php | 93 |
1 files changed, 17 insertions, 76 deletions
diff --git a/lib/watermark.php b/lib/watermark.php index 160dd48b4..13eb598a0 100644 --- a/lib/watermark.php +++ b/lib/watermark.php @@ -45,103 +45,44 @@ function tp_gd_watermark($image) { $top = $image_height - $line_height - 10; $left = round(($image_width - $line_width) / 2); - $textcolor = imagecolorallocate($image, 50, 50, 50); + imagealphablending($image, true); + $textcolor = imagecolorallocatealpha($image, 50, 50, 50, 50); imagestring($image, $font, $left, $top, $watermark_text, $textcolor); } function tp_imagick_watermark($filename) { + $watermark_text = get_plugin_setting('watermark_text', 'tidypics'); if (!$watermark_text) return; - - $owner = get_loggedin_user(); $watermark_text = tp_process_watermark_text($watermark_text, $owner); - $ext = ".png"; - - $user_stamp_base = tp_get_watermark_filename($watermark_text, $owner); + $img = new Imagick($filename); - $watermark = array(); - $image = new Imagick($filename); - $draw = new ImagickDraw(); - $draw->setGravity(Imagick::GRAVITY_CENTER); - # $draw->setFont($font); - # $draw->setFontSize($font_size); - $textColor = new ImagickPixel("black"); - $draw->setFillColor($textColor); - - $im = new imagick(); - $properties = $im->queryFontMetrics($draw, $watermark_text); - $watermark['w'] = intval($properties["textWidth"] + 5); - $watermark['h'] = intval($properties["textHeight"] + 5); - $im->newImage($watermark['w'],$watermark['h'],new ImagickPixel("transparent")); - $im->setImageFormat("jpg"); - $im->annotateImage($draw, 0, 0, 0, $watermark_text); - $watermark = $im->clone(); - $watermark->setImageBackgroundColor($textColor); - $watermark->shadowImage(80, 2, 2, 2); - $watermark->compositeImage($im, Imagick::COMPOSITE_OVER, 0, 0); - $image->compositeImage($watermark, Imagick::COMPOSITE_OVER, 0, 0); - - if ($image->writeImage($filename) != true) { - $image->destroy(); - return false; - } - - $image->destroy(); -/* - if ( !file_exists( $user_stamp_base . $ext )) { //create the watermark if it doesn't exist + $img->readImage($image); - $commands = array(); - $commands[] = $im_path . 'convert -size 300x50 xc:grey30 -pointsize 20 -gravity center -draw "fill grey70 text 0,0 \''. $watermark_text . '\'" "'. $user_stamp_base . '_fgnd' . $ext . '"'; - $commands[] = $im_path . 'convert -size 300x50 xc:black -pointsize 20 -gravity center -draw "fill white text 1,1 \''. $watermark_text . '\' text 0,0 \''. $watermark_text . '\' fill black text -1,-1 \''. $watermark_text . '\'" +matte ' . $user_stamp_base . '_mask' . $ext; - $commands[] = $im_path . 'composite -compose CopyOpacity "' . $user_stamp_base . "_mask" . $ext . '" "' . $user_stamp_base . '_fgnd' . $ext . '" "' . $user_stamp_base . $ext . '"'; - $commands[] = $im_path . 'mogrify -trim +repage "' . $user_stamp_base . $ext . '"'; - $commands[] = 'rm "' . $user_stamp_base . '_mask' . $ext . '"'; - $commands[] = 'rm "' . $user_stamp_base . '_fgnd' . $ext . '"'; - - foreach( $commands as $command ) { - exec( $command ); - } + $draw = new ImagickDraw(); - } -*/ -/* - try { - $img = new Imagick($filename); - } catch (ImagickException $e) { - return false; - } - - try { - $mask = new Imagick($user_stamp_base . $ext); - } catch (ImagickException $e) { - return false; - } - - $image_width = $img->getImageWidth(); - $image_height = $img->getImageHeight(); - $mask_width = $mask->getImageWidth(); - $mask_height = $mask->getImageHeight(); - - // matching -gravity south -geometry +0+10 - $top = $image_height - $mask_height - 10; - $left = round(($image_width - $mask_width) / 2); - - $img->compositeImage($mask, Imagick::COMPOSITE_DEFAULT, $left, $top); - - $mask->destroy(); - + //$draw->setFont(""); + + $draw->setFontSize(28); + + $draw->setFillOpacity(0.5); + + $draw->setGravity(Imagick::GRAVITY_SOUTH); + + $img->annotateImage($draw, 0, 0, 0, $watermark_text); + if ($img->writeImage($filename) != true) { $img->destroy(); return false; } $img->destroy(); -*/ + return true; } |