Rename Horde_Image_Imagick::borderImage to ::frameImage
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 31 May 2009 15:30:59 +0000 (11:30 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 31 May 2009 15:33:11 +0000 (11:33 -0400)
Rename this function and only use it when we are bordering a transparent
image (i.e. Framing an image) and not when applying a traditional borderImage
operation (which replaces all pixels in the clipping area). This should
provide a noticeable speed improvement with some effects

framework/Image/lib/Horde/Image/Effect/Imagick/Border.php
framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php
framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php
framework/Image/lib/Horde/Image/Effect/Imagick/RoundCorners.php
framework/Image/lib/Horde/Image/Imagick.php

index aa47ac1..41d72a2 100755 (executable)
@@ -29,10 +29,18 @@ class Horde_Image_Effect_Imagick_Border extends Horde_Image_Effect
      */
     public function apply()
     {
-        Horde_Image_Imagick::borderImage($this->_image->imagick,
-                                         $this->_params['bordercolor'],
-                                         $this->_params['borderwidth'],
-                                         $this->_params['borderwidth']);
+        if ($this->_params['preserve']) {
+            Horde_Image_Imagick::frameImage($this->_image->imagick,
+                                             $this->_params['bordercolor'],
+                                             $this->_params['borderwidth'],
+                                             $this->_params['borderwidth']);
+        } else {
+            $this->_image->imagick->borderImage(
+                new ImagickPixel($this->_params['bordercolor']),
+                $this->_params['borderwidth'],
+                $this->_params['borderwidth']);
+        }
+
         return true;
     }
 
index 1e06182..864ce6c 100644 (file)
@@ -43,29 +43,12 @@ class Horde_Image_Effect_Imagick_DropShadow extends Horde_Image_Effect
                              $this->_params['distance'],
                              $this->_params['distance']);
 
-
-        // If we have an actual background color, we need to explicitly
-        // create a new background image with that color to be sure there
-        // *is* a background color.
-        if ($this->_params['background'] != 'none') {
-            $size = $shadow->getImageGeometry();
-            $new = new Imagick();
-            $new->newImage($size['width'], $size['height'], new ImagickPixel($this->_params['background']));
-            $new->setImageFormat($this->_image->getType());
-
-            $new->compositeImage($shadow, Imagick::COMPOSITE_OVER, 0, 0);
-            $shadow->clear();
-            $shadow->addImage($new);
-            $new->destroy();
-        }
-
         $shadow->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0);
 
         if ($this->_params['padding']) {
-            Horde_Image_Imagick::borderImage($shadow,
-                                             $this->_params['background'],
-                                             $this->_params['padding'],
-                                             $this->_params['padding']);
+            $shadow->borderImage($this->_params['background'],
+                                                $this->_params['padding'],
+                                                $this->_params['padding']);
         }
         $this->_image->imagick->clear();
         $this->_image->imagick->addImage($shadow);
index 35d0908..28b1913 100644 (file)
@@ -93,21 +93,20 @@ class Horde_Image_Effect_Imagick_PhotoStack extends Horde_Image_Effect
                 $imgk= new Imagick();
                 $imgk->clear();
                 $imgk->readImageBlob($image->raw());
+                // Either resize the thumbnail to match the top image or we *are*
+                // the top image already.
                 if ($i++ <= $cnt) {
-                    $imgk->thumbnailImage($size['width'], $size['height'],
-                                          false);
+                    $imgk->thumbnailImage($size['width'], $size['height'], false);
                 } else {
                     $imgk->destroy();
                     $imgk = $topimg->clone();
                 }
-
                 if ($this->_params['type'] == 'rounded') {
                     $imgk = $this->_roundBorder($imgk);
                 } else {
-                    Horde_Image_Imagick::borderImage($imgk,
-                                                     $this->_params['bordercolor'],
-                                                     $this->_params['borderwidth'],
-                                                     $this->_params['borderwidth']);
+                    $imgk->borderImage($this->_params['bordercolor'],
+                                       $this->_params['borderwidth'],
+                                       $this->_params['borderwidth']);
                 }
                 // Only shadow the bottom image for 'plain' stacks
                 if (!$haveBottom) {
@@ -184,21 +183,6 @@ class Horde_Image_Effect_Imagick_PhotoStack extends Horde_Image_Effect
             $image->destroy();
         }
 
-        //@TODO: Was this here for BC with Imagick compiled against older Im?
-        // Remove this after I checked against my older IM install
-        // If we have a background other than 'none' we need to
-        // compose two images together to make sure we *have* a background.
-//        if ($this->_params['background'] != 'none') {
-//            $size = $this->_image->getDimensions();
-//            $new = new Imagick();
-//            $new->newImage($length * 1.5 + 20, $length * 1.5 + 20, new ImagickPixel($this->_params['background']));
-//            $new->setImageFormat($this->_image->getType());
-//            $new->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0);
-//            $this->_image->imagick->clear();
-//            $this->_image->imagick->addImage($new);
-//            $new->destroy();
-//        }
-
         // Trim the canvas before resizing to keep the thumbnails as large
         // as possible.
         $this->_image->imagick->trimImage(0);
@@ -207,13 +191,6 @@ class Horde_Image_Effect_Imagick_PhotoStack extends Horde_Image_Effect
                 new ImagickPixel($this->_params['background']),
                 $this->_params['padding'],
                 $this->_params['padding']);
-
-            // @TODO: Same here, did I do this for older Im versions not working
-            // right?
-            //Horde_Image_Imagick::borderImage($this->_image->imagick,
-            //                                 $this->_params['background'],
-            //                                 $this->_params['padding'],
-            //                                 $this->_params['padding']);
         }
 
         return true;
index f5b76ef..31d28ea 100644 (file)
@@ -50,7 +50,9 @@ class Horde_Image_Effect_Imagick_RoundCorners extends Horde_Image_Effect
         }
 
         // If we have a background other than 'none' we need to
-        // compose two images together to make sure we *have* a background.
+        // compose two images together to make sure we *have* a background. We
+        // can't use border because we don't want to extend the image area, just
+        // fill in the parts removed by the rounding.
         if ($this->_params['background'] != 'none') {
             $size = $this->_image->getDimensions();
             $new = new Imagick();
index 2202774..e725e21 100644 (file)
@@ -396,8 +396,9 @@ class Horde_Image_Imagick extends Horde_Image
     }
 
     /**
-     * Utility function to wrap Imagick::borderImage so we can preserve any
-     * transparency in the image.
+     * Utility function to wrap Imagick::borderImage. Use when you don't want
+     * to replace all pixels in the clipping area with the border color i.e.
+     * you want to "frame" the existing image. Preserves transparency etc...
      *
      * @param Imagick &$image  The Imagick object to border.
      * @param integer $width
@@ -405,7 +406,7 @@ class Horde_Image_Imagick extends Horde_Image
      *
      * @return void
      */
-    static public function borderImage(&$image, $color, $width, $height)
+    static public function frameImage(&$image, $color, $width, $height)
     {
          // Need to jump through these hoops in order to preserve any
         // transparency.