[ansel] Patch for watermark placeholders and GD fonts

Heath S. Hendrickson heath at outerspaceconsultants.com
Fri Mar 19 12:16:02 PST 2004


Attached are patches to files to add the following functionality to Ansel:

1) watermark placeholders.  these include the standard strftime() 
placeholders as well as %N => Users Full Name and %L => Users login name.

2) ability to set the gd font that is used in the custom watermark 
pop-up.  Choices are limited to the 5 builtin fonts for GD (tiny, small, 
medium, large, giant).   It currently only works if you are using GD 
(but then again, watermarks only work if you are using GD...)

Files modified:

../framework/Image/Image.php
image.php
templates/image/preview_image.inc
templates/image/edit_image.inc
lib/Gallery.php

h
-------------- next part --------------
Index: lib/Gallery.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/lib/Gallery.php,v
retrieving revision 1.50
diff -u -r1.50 Gallery.php
--- lib/Gallery.php	8 Mar 2004 19:17:54 -0000	1.50
+++ lib/Gallery.php	19 Mar 2004 19:22:57 -0000
@@ -837,7 +837,7 @@
      *
      * @param optional string $watermark  String to use as the watermark.
      */
-    function watermark($watermark = null)
+    function watermark($watermark = null, $halign = null, $valign = null, $font = null)
     {
         if (empty($watermark)) {
             require_once HORDE_LIBS . 'Horde/Identity.php';
@@ -851,7 +851,7 @@
 
         $this->load();
         $this->_dirty = true;
-        return $this->_image->watermark($watermark);
+        return $this->_image->watermark($watermark, $halign, $valign, $font);
     }
 
     /**
-------------- next part --------------
Index: ../framework/Image/Image/gd.php
===================================================================
RCS file: /usr/local/horde/cvs/framework/Image/Image/gd.php,v
retrieving revision 1.35
diff -u -r1.35 gd.php
--- ../framework/Image/Image/gd.php	4 Feb 2004 16:11:52 -0000	1.35
+++ ../framework/Image/Image/gd.php	19 Mar 2004 19:24:54 -0000
@@ -153,7 +153,26 @@
 
     function getFont($font)
     {
-        return 2;
+        switch ($font) {
+            case 'tiny':
+                return 1;
+                break;
+            case 'small';
+                return 2;
+                break;
+            case 'medium':
+                return 3;
+                break;
+            case 'large':
+                return 4;
+                break;
+            case 'giant':
+                return 5;
+                break;
+            default:
+                return 2;
+        }
+        //return 2;
     }
 
     function loadString($id, $image_data)
@@ -451,7 +470,7 @@
         }
     }
 
-    function watermark($text, $halign = 'right', $valign = 'bottom')
+    function watermark($text, $halign = 'right', $valign = 'bottom', $font = 'small')
     {
         $color = imageColorClosest($this->_im, 255, 255, 255);
         $shadow = imageColorClosest($this->_im, 0, 0, 0);
@@ -466,7 +485,7 @@
         // border.
         $padding = 10;
 
-        $f = $this->getFont('arial');
+        $f = $this->getFont($font);
         $fontwidth = imageFontWidth($f);
         $fontheight = imageFontHeight($f);
 
-------------- next part --------------
Index: image.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/image.php,v
retrieving revision 1.68
diff -u -r1.68 image.php
--- image.php	16 Mar 2004 02:51:17 -0000	1.68
+++ image.php	19 Mar 2004 20:00:29 -0000
@@ -100,6 +100,23 @@
 
         $w = &$this->addVariable(_("Custom Watermark"), 'watermark', 'text', false, false, null);
         $w->setDefault($prefs->getValue('watermark'));
+
+        $fonts = array('tiny' => _("Tiny"),'small' => _("Small"),'medium' => _("Medium"),'large' => _("Large"),'giant' => _("Giant"));
+        $f = &$this->addVariable(_("Watermark Font"), 'font', 'enum', false, false, null, array($fonts));
+        if ($prefs->getValue('font')) {
+            $default_font = $prefs->getValue('font');
+        } else {
+            $default_font = 'small';
+        }
+        $f->setDefault($default_font);
+
+        $ha = array( 'left' => _('Left'), 'center' => _("Center"), 'right' => _("Right") );
+        $wha = &$this->addVariable(_("Horizontal Alignment"), 'whalign', 'enum', false, false, null, array($ha));
+        $wha->setDefault('right');
+
+        $va = array( 'top' => _('Top'), 'middle' => _("Middle"), 'bottom' => _("Bottom") );
+        $wva = &$this->addVariable(_("Vertical Alignment"), 'wvalign', 'enum', false, false, null, array($va));
+        $wva->setDefault('bottom');
     }
 
 }
@@ -108,7 +125,24 @@
 $gallery_id = Util::getFormData('gallery');
 $image_id = Util::getFormData('image');
 $watermark = Util::getFormData('watermark', $prefs->getValue('watermark'));
+$watermark_halign = Util::getFormData('whalign');
+$watermark_valign = Util::getFormData('wvalign');
+//$watermark_transp = Util::getFormData('wtransp');
+if (isset($watermark)) {
+    require_once HORDE_LIBS . 'Horde/Identity.php';
+    $identity = &Identity::singleton();
+    $name = $identity->getValue('fullname');
+    if (empty($name)) {
+        $name = Auth::getAuth();
+    }
+    // set up array of possible substitutions
+    $watermark_array = array('%N' => $name,   // Users fullname
+                            '%L' => Auth::getAuth());   // user login
+    $watermark = strftime( $watermark );
+    $watermark = str_replace(array_keys($watermark_array), array_values($watermark_array), $watermark);
+}
 $page = Util::getFormData('page', 0);
+$watermark_font = Util::getFormData('font');
 
 /* Redirect to the image list if no action has been requested. */
 if (is_null($actionID)) {
@@ -369,7 +403,7 @@
             break;
 
         case 'watermark':
-            $image->watermark($watermark);
+            $image->watermark($watermark, $watermark_halign, $watermark_valign, $watermark_font);
             break;
         }
 
@@ -405,6 +439,9 @@
     $imageurl = Util::addParameter($imageurl, 'image', $image_id);
     $imageurl = Util::addParameter($imageurl, 'page', $page);
     $imageurl = Util::addParameter($imageurl, 'watermark', $watermark);
+    $imageurl = Util::addParameter($imageurl, 'font', $watermark_font);
+    $imageurl = Util::addParameter($imageurl, 'whalign', $watermark_halign);
+    $imageurl = Util::addParameter($imageurl, 'wvalign', $watermark_valign);
     $url = Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'previewwatermark'));
     $url = str_replace( '&', '&', $url);
     Util::closeWindowJS('window.opener.location.href = "' . $url . '";');
@@ -468,7 +505,7 @@
 
 case 'imagewatermark':
     $image = &$ansel_shares->getImageById($image_id);
-    $image->watermark($watermark);
+    $image->watermark($watermark, $watermark_halign, $watermark_valign, $watermark_font);
     $image->display();
     exit;
 
-------------- next part --------------
Index: templates/image/preview_image.inc
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/image/preview_image.inc,v
retrieving revision 1.10
diff -u -r1.10 preview_image.inc
--- templates/image/preview_image.inc	12 Feb 2004 19:04:41 -0000	1.10
+++ templates/image/preview_image.inc	19 Mar 2004 19:50:47 -0000
@@ -9,6 +9,9 @@
 $base_url = Util::addParameter($base_url, 'image', $image_id);
 $base_url = Util::addParameter($base_url, 'page', $page);
 $base_url = Util::addParameter($base_url, 'watermark', $watermark);
+$base_url = Util::addParameter($base_url, 'whalign', $watermark_halign);
+$base_url = Util::addParameter($base_url, 'wvalign', $watermark_valign);
+$base_url = Util::addParameter($base_url, 'font', $watermark_font);
 
 $edit_url = Util::addParameter($base_url, 'actionID', 'editimage');
 $save_url = Util::addParameter($base_url, 'actionID', $action);
-------------- next part --------------
Index: templates/image/edit_image.inc
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/image/edit_image.inc,v
retrieving revision 1.19
diff -u -r1.19 edit_image.inc
--- templates/image/edit_image.inc	12 Feb 2004 19:04:41 -0000	1.19
+++ templates/image/edit_image.inc	19 Mar 2004 19:58:36 -0000
@@ -36,7 +36,7 @@
     }
     if (Ansel::isAvailable('watermark')) {
         Horde::addScriptFile('popup.js', 'horde');
-        echo Menu::createItem('javascript:popup(\'' . Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'setwatermark'), 'share', $gallery->getName()) . '\', 600, 100);', _("Watermark"), 'text.png', null, null, null, 'control', 'widget');
+        echo Menu::createItem('javascript:popup(\'' . Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'setwatermark'), 'share', $gallery->getName()) . '\', 450, 250);', _("Watermark"), 'text.png', null, null, null, 'control', 'widget');
     }
 }
 if ($gallery->hasPermission(Auth::getAuth(), PERMS_DELETE)) {


More information about the ansel mailing list