diff options
Diffstat (limited to 'lib/watermark.php')
-rw-r--r-- | lib/watermark.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/watermark.php b/lib/watermark.php index 91e2a38f3..b80e1b9e9 100644 --- a/lib/watermark.php +++ b/lib/watermark.php @@ -26,6 +26,70 @@ function tp_gd_watermark($filename) { } 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); + + + if ( !file_exists( $user_stamp_base . $ext )) { //create the watermark if it doesn't exist +/* + $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 ); + } +*/ + } + + 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(); + + if ($img->writeImage($filename) != true) { + $img->destroy(); + return false; + } + + $img->destroy(); + + return true; } function tp_imagick_cmdline_watermark($filename) { |