aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2009-09-09 01:44:34 +0000
committerCash Costello <cash.costello@gmail.com>2009-09-09 01:44:34 +0000
commitabb0bcd5c36a43ebc7bc5ed41c197566ed585113 (patch)
tree2c3cbf4721a2e5db1156d6e82027a91fc2693ef3
parentefa3b16151f59d57b7ac8280f10b5db83c29ce97 (diff)
downloadelgg-abb0bcd5c36a43ebc7bc5ed41c197566ed585113.tar.gz
elgg-abb0bcd5c36a43ebc7bc5ed41c197566ed585113.tar.bz2
getting back to working on watermarking
-rw-r--r--lib/watermark.php43
-rw-r--r--views/default/tidypics/forms/settings.php2
2 files changed, 36 insertions, 9 deletions
diff --git a/lib/watermark.php b/lib/watermark.php
index 2263bdd8f..160dd48b4 100644
--- a/lib/watermark.php
+++ b/lib/watermark.php
@@ -3,7 +3,7 @@
function tp_process_watermark_text($text, $owner) {
global $CONFIG;
- $text = str_replace("%username%", $owner->username, $text);
+ $text = str_replace("%name%", $owner->name, $text);
$text = str_replace("%sitename%", $CONFIG->sitename, $text);
return $text;
@@ -45,7 +45,7 @@ function tp_gd_watermark($image) {
$top = $image_height - $line_height - 10;
$left = round(($image_width - $line_width) / 2);
- $textcolor = imagecolorallocate($image, 0, 0, 255);
+ $textcolor = imagecolorallocate($image, 50, 50, 50);
imagestring($image, $font, $left, $top, $watermark_text, $textcolor);
}
@@ -63,10 +63,38 @@ function tp_imagick_watermark($filename) {
$ext = ".png";
$user_stamp_base = tp_get_watermark_filename($watermark_text, $owner);
+
+ $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;
+ }
-
- if ( !file_exists( $user_stamp_base . $ext )) { //create the watermark if it doesn't exist
+ $image->destroy();
/*
+ 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;
@@ -78,9 +106,10 @@ function tp_imagick_watermark($filename) {
foreach( $commands as $command ) {
exec( $command );
}
-*/
- }
+ }
+*/
+/*
try {
$img = new Imagick($filename);
} catch (ImagickException $e) {
@@ -112,7 +141,7 @@ function tp_imagick_watermark($filename) {
}
$img->destroy();
-
+*/
return true;
}
diff --git a/views/default/tidypics/forms/settings.php b/views/default/tidypics/forms/settings.php
index 9565ddb1f..6ab9dfcc9 100644
--- a/views/default/tidypics/forms/settings.php
+++ b/views/default/tidypics/forms/settings.php
@@ -70,10 +70,8 @@
$form_body .= '<p class="admin_debug">' . elgg_view("input/checkboxes", array('options' => array(elgg_echo('tidypics:settings:view_count') => 'enabled'), 'internalname' => 'view_count', 'value' => $view_count )) . "</p>";
// Watermark Text
-/*
$form_body .= "<p>" . elgg_echo('tidypics:settings:watermark') . "<br />";
$form_body .= elgg_view("input/text",array('internalname' => 'params[watermark_text]', 'value' => $plugin->watermark_text)) . "</p>";
-*/
// Max Image Size
$maxfilesize = $plugin->maxfilesize;