aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2009-07-12 01:27:26 +0000
committerCash Costello <cash.costello@gmail.com>2009-07-12 01:27:26 +0000
commit6f542ab26ea4bc65ae33a691802d233d8dafa592 (patch)
treead5eef7a8628e4807fd0aa52e1b138c86cc0ea27 /lib
parent533231ec979a907cab73e27013da5f9d69b22121 (diff)
downloadelgg-6f542ab26ea4bc65ae33a691802d233d8dafa592.tar.gz
elgg-6f542ab26ea4bc65ae33a691802d233d8dafa592.tar.bz2
cleaned up the command line watermarking code
Diffstat (limited to 'lib')
-rw-r--r--lib/resize.php10
-rw-r--r--lib/watermark.php86
2 files changed, 54 insertions, 42 deletions
diff --git a/lib/resize.php b/lib/resize.php
index a379d8c93..894a68fff 100644
--- a/lib/resize.php
+++ b/lib/resize.php
@@ -66,6 +66,8 @@
if (!$rtn_code)
return false;
$file->largethumb = $prefix."largethumb".$filestorename;
+
+ tp_gd_watermark($thumbname);
unset($thumb);
@@ -252,6 +254,8 @@
if (!$rtn_code)
return false;
$file->largethumb = $prefix."largethumb".$filestorename;
+
+ tp_imagick_watermark($thumbname);
unset($thumb);
@@ -422,9 +426,9 @@
return false;
$file->largethumb = $prefix."largethumb".$filestorename;
-
- //tp_watermark($thumbs);
-
+
+ tp_imagick_cmdline_watermark($thumbname);
+
unset($thumb);
diff --git a/lib/watermark.php b/lib/watermark.php
index 25eb52d48..b60bae88e 100644
--- a/lib/watermark.php
+++ b/lib/watermark.php
@@ -1,55 +1,63 @@
<?php
+function tp_gd_watermark($filename) {
+}
+
+function tp_imagick_watermark($filename) {
+}
-function tp_watermark($thumbs) {
+function tp_imagick_cmdline_watermark($filename) {
global $CONFIG;
- $user = get_user_entity_as_row($album->owner_guid);
- $username = $user->username;
+ $watermark_text = get_plugin_setting('watermark_text', 'tidypics');
+ if (!$watermark_text)
+ return;
+
$im_path = get_plugin_setting('im_path', 'tidypics');
- if(!$im_path) {
+ if (!$im_path) {
$im_path = "/usr/bin/";
}
- if(substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";
- $viewer = get_loggedin_user();
- $watermark_text = get_plugin_setting('watermark_text', 'tidypics');
- $watermark_text = str_replace("%username%", $viewer->username, $watermark_text);
+ // make sure end of path is /
+ if (substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";
+
+
+ $owner = get_loggedin_user();
+
+
+ $watermark_text = str_replace("%username%", $owner->username, $watermark_text);
$watermark_text = str_replace("%sitename%", $CONFIG->sitename, $watermark_text);
- if( $watermark_text ) { //get this value from the plugin settings
- if( $thumbs["thumblarge"] ) {
- $ext = ".png";
-
- $watermark_filename = strtolower($watermark_text);
- $watermark_filename = preg_replace("/[^\w-]+/", "-", $watermark_filename);
- $watermark_filename = trim($watermark_filename, '-');
-
- $user_stamp_base = tp_get_img_dir();
- $user_stamp_base .= strtolower($viewer->name . "_" . $watermark_filename . "_stamp");
-
- 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 );
- }
- }
- //apply the watermark
- $commands = array();
- $commands[] = $im_path . 'composite -gravity south -geometry +0+10 "' . $user_stamp_base . $ext . '" "' . $thumbs["thumblarge"] . '" "' . $thumbs["thumblarge"] . '_watermarked"';
- $commands[] = "mv \"$thumbs[thumblarge]" . "_watermarked\" \"$thumbs[thumblarge]\"";
- foreach( $commands as $command ) {
- exec( $command );
- }
+ $ext = ".png";
+
+ $watermark_filename = strtolower($watermark_text);
+ $watermark_filename = preg_replace("/[^\w-]+/", "-", $watermark_filename);
+ $watermark_filename = trim($watermark_filename, '-');
+
+ $user_stamp_base = tp_get_img_dir();
+ $user_stamp_base .= strtolower($owner->username . "_" . $watermark_filename . "_stamp");
+
+ 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 );
}
}
+
+ //apply the watermark
+ $commands = array();
+ $commands[] = $im_path . 'composite -gravity south -geometry +0+10 "' . $user_stamp_base . $ext . '" "' . $filename . '" "' . $filename . '_watermarked"';
+ $commands[] = "mv \"$filename" . "_watermarked\" \"$filename\"";
+ foreach( $commands as $command ) {
+ exec( $command );
+ }
}
?> \ No newline at end of file