get rid of remaining PEAR_Error in Horde_Image
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 8 Jul 2010 14:51:56 +0000 (10:51 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 8 Jul 2010 14:51:56 +0000 (10:51 -0400)
framework/Image/lib/Horde/Image/Base.php
framework/Image/lib/Horde/Image/Effect/Gd/DropShadow.php
framework/Image/lib/Horde/Image/Effect/Gd/RoundCorners.php
framework/Image/lib/Horde/Image/Effect/Gd/TextWatermark.php
framework/Image/lib/Horde/Image/Effect/Gd/UnsharpMask.php
framework/Image/lib/Horde/Image/Effect/Im/DropShadow.php
framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php
framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php
framework/Image/tests/im.php

index 85bd7fb..1ea55e7 100644 (file)
@@ -328,13 +328,12 @@ abstract class Horde_Image_Base extends EmptyIterator
     }
 
     /**
-     * Attempts to apply requested effect to this image.  If the
-     * effect cannot be found a PEAR_Error is returned.
+     * Attempts to apply requested effect to this image.
      *
      * @param string $type    The type of effect to apply.
      * @param array $params   Any parameters for the effect.
      *
-     * @return mixed  true on success | PEAR_Error on failure.
+     * @return boolean
      */
     public function addEffect($type, $params)
     {
index b18269c..9850dc8 100644 (file)
@@ -28,7 +28,7 @@ class Horde_Image_Effect_Gd_DropShadow extends Horde_Image_Effect
     /**
      * Apply the drop_shadow effect.
      *
-     * @return mixed true | PEAR_Error
+     * @return boolean
      */
     public function apply()
     {
@@ -49,75 +49,61 @@ class Horde_Image_Effect_Gd_DropShadow extends Horde_Image_Effect
 
         $tempImageWidth  = $imgX  + abs($offset['x']);
         $tempImageHeight = $imgY + abs($offset['y']);
-        $gdimg_dropshadow_temp = $this->_image->create($tempImageWidth,
-                                                        $tempImageHeight);
-        if (!is_a($gdimg_dropshadow_temp, 'PEAR_Error')) {
-            $this->_image->call('imageAlphaBlending',
-                                 array($gdimg_dropshadow_temp, false));
-
-            $this->_image->call('imageSaveAlpha',
-                                 array($gdimg_dropshadow_temp, true));
-
-            $transparent1 = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, 0, 0, 0, 127));
-
-            if (is_a($transparent1, 'PEAR_Error')) {
-                return $transparent1;
+        $gdimg_dropshadow_temp = $this->_image->create($tempImageWidth, $tempImageHeight);
+        $this->_image->call('imageAlphaBlending', array($gdimg_dropshadow_temp, false));
+        $this->_image->call('imageSaveAlpha', array($gdimg_dropshadow_temp, true));
+        $transparent1 = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, 0, 0, 0, 127));
+        $this->_image->call('imageFill', array($gdimg_dropshadow_temp, 0, 0, $transparent1));
+        for ($x = 0; $x < $imgX; $x++) {
+            for ($y = 0; $y < $imgY; $y++) {
+                $colorat = $this->_image->call('imageColorAt', array($gdimg, $x, $y));
+                $PixelMap[$x][$y] = $this->_image->call('imageColorsForIndex', array($gdimg, $colorat));
             }
+        }
 
-            $this->_image->call('imageFill',
-                                 array($gdimg_dropshadow_temp, 0, 0, $transparent1));
-
-            for ($x = 0; $x < $imgX; $x++) {
-                for ($y = 0; $y < $imgY; $y++) {
-                    $colorat = $this->_image->call('imageColorAt', array($gdimg, $x, $y));
-                    $PixelMap[$x][$y] = $this->_image->call('imageColorsForIndex',
-                                                             array($gdimg, $colorat));
-                }
-            }
-
-            /* Creates the shadow */
-            $r = hexdec(substr($hexcolor, 0, 2));
-            $g = hexdec(substr($hexcolor, 2, 2));
-            $b = hexdec(substr($hexcolor, 4, 2));
-
-            /* Essentially masks the original image and creates the shadow */
-            for ($x = 0; $x < $tempImageWidth; $x++) {
-                for ($y = 0; $y < $tempImageHeight; $y++) {
-                        if (!isset($PixelMap[$x][$y]['alpha']) ||
-                            ($PixelMap[$x][$y]['alpha'] > 0)) {
-                            if (isset($PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha']) && ($PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha'] < 127)) {
-                                $thisColor = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, $r, $g, $b, $PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha']));
-                                $this->_image->call('imageSetPixel',
-                                                     array($gdimg_dropshadow_temp, $x, $y, $thisColor));
-                            }
+        /* Creates the shadow */
+        $r = hexdec(substr($hexcolor, 0, 2));
+        $g = hexdec(substr($hexcolor, 2, 2));
+        $b = hexdec(substr($hexcolor, 4, 2));
+
+        /* Essentially masks the original image and creates the shadow */
+        for ($x = 0; $x < $tempImageWidth; $x++) {
+            for ($y = 0; $y < $tempImageHeight; $y++) {
+                    if (!isset($PixelMap[$x][$y]['alpha']) ||
+                        ($PixelMap[$x][$y]['alpha'] > 0)) {
+                        if (isset($PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha']) && ($PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha'] < 127)) {
+                            $thisColor = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, $r, $g, $b, $PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha']));
+                            $this->_image->call('imageSetPixel',
+                                                 array($gdimg_dropshadow_temp, $x, $y, $thisColor));
                         }
-                }
-            }
-            /* Overlays the original image */
-            $this->_image->call('imageAlphaBlending',
-                                 array($gdimg_dropshadow_temp, true));
-
-            for ($x = 0; $x < $imgX; $x++) {
-                for ($y = 0; $y < $imgY; $y++) {
-                    if ($PixelMap[$x][$y]['alpha'] < 127) {
-                        $thisColor = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, $PixelMap[$x][$y]['red'], $PixelMap[$x][$y]['green'], $PixelMap[$x][$y]['blue'], $PixelMap[$x][$y]['alpha']));
-                        $this->_image->call('imageSetPixel',
-                                             array($gdimg_dropshadow_temp, $x, $y, $thisColor));
                     }
+            }
+        }
+        /* Overlays the original image */
+        $this->_image->call('imageAlphaBlending',
+                             array($gdimg_dropshadow_temp, true));
+
+        for ($x = 0; $x < $imgX; $x++) {
+            for ($y = 0; $y < $imgY; $y++) {
+                if ($PixelMap[$x][$y]['alpha'] < 127) {
+                    $thisColor = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, $PixelMap[$x][$y]['red'], $PixelMap[$x][$y]['green'], $PixelMap[$x][$y]['blue'], $PixelMap[$x][$y]['alpha']));
+                    $this->_image->call('imageSetPixel',
+                                         array($gdimg_dropshadow_temp, $x, $y, $thisColor));
                 }
             }
+        }
 
-            $this->_image->call('imageSaveAlpha',
-                                 array($gdimg, true));
-            $this->_image->call('imageAlphaBlending',
-                                 array($gdimg, false));
+        $this->_image->call('imageSaveAlpha',
+                             array($gdimg, true));
+        $this->_image->call('imageAlphaBlending',
+                             array($gdimg, false));
 
-            // Merge the shadow and the original into the original.
-            $this->_image->call('imageCopyResampled',
-                                 array($gdimg, $gdimg_dropshadow_temp, 0, 0, 0, 0, $imgX, $imgY, $this->_image->call('imageSX', array($gdimg_dropshadow_temp)), $this->_image->call('imageSY', array($gdimg_dropshadow_temp))));
+        // Merge the shadow and the original into the original.
+        $this->_image->call('imageCopyResampled',
+                             array($gdimg, $gdimg_dropshadow_temp, 0, 0, 0, 0, $imgX, $imgY, $this->_image->call('imageSX', array($gdimg_dropshadow_temp)), $this->_image->call('imageSY', array($gdimg_dropshadow_temp))));
+
+        $this->_image->call('imageDestroy', array($gdimg_dropshadow_temp));
 
-            $this->_image->call('imageDestroy', array($gdimg_dropshadow_temp));
-        }
         return true;
     }
 
index b4494d4..5687aa3 100644 (file)
@@ -25,7 +25,7 @@ class Horde_Image_Effect_Gd_RoundCorners extends Horde_Image_Effect
     /**
      * Apply the round_corners effect.
      *
-     * @return mixed true | PEAR_Error
+     * @return boolean
      */
     public function apply()
     {
@@ -39,97 +39,83 @@ class Horde_Image_Effect_Gd_RoundCorners extends Horde_Image_Effect
         $gdimg = $this->_image->_im;
         $imgX = round($this->_image->call('imageSX', array($gdimg)));
         $imgY = round($this->_image->call('imageSY', array($gdimg)));
+        $gdimg_cornermask_triple = $this->_image->create(round($radius_x * 6), round($radius_y * 6));
+        $gdimg_cornermask = $this->_image->create($imgX, $imgY);
+        $color_transparent = $this->_image->call('imageColorAllocate',
+                                                  array($gdimg_cornermask_triple,
+                                                        255,
+                                                        255,
+                                                        255));
 
-        $gdimg_cornermask_triple = $this->_image->create(round($radius_x * 6),
-                                                          round($radius_y * 6));
-        if (!is_a($gdimg_cornermask_triple, 'PEAR_Error')) {
+        $this->_image->call('imageFilledEllipse',
+                             array($gdimg_cornermask_triple,
+                                   $radius_x * 3,
+                                   $radius_y * 3,
+                                   $radius_x * 4,
+                                   $radius_y * 4,
+                                   $color_transparent));
 
-            $gdimg_cornermask = $this->_image->create($imgX, $imgY);
-            if (!is_a($gdimg_cornermask, 'PEAR_Error')) {
-                $color_transparent = $this->_image->call('imageColorAllocate',
-                                                          array($gdimg_cornermask_triple,
-                                                                255,
-                                                                255,
-                                                                255));
+        $this->_image->call('imageFilledRectangle',
+                             array($gdimg_cornermask,
+                                   0,
+                                   0,
+                                   $imgX,
+                                   $imgY,
+                                   $color_transparent));
 
-                $this->_image->call('imageFilledEllipse',
-                                     array($gdimg_cornermask_triple,
-                                           $radius_x * 3,
-                                           $radius_y * 3,
-                                           $radius_x * 4,
-                                           $radius_y * 4,
-                                           $color_transparent));
+        $this->_image->call('imageCopyResampled',
+                             array($gdimg_cornermask,
+                                   $gdimg_cornermask_triple,
+                                   0,
+                                   0,
+                                   $radius_x,
+                                   $radius_y,
+                                   $radius_x,
+                                   $radius_y,
+                                   $radius_x * 2,
+                                   $radius_y * 2));
 
-                $this->_image->call('imageFilledRectangle',
-                                     array($gdimg_cornermask,
-                                           0,
-                                           0,
-                                           $imgX,
-                                           $imgY,
-                                           $color_transparent));
+        $this->_image->call('imageCopyResampled',
+                             array($gdimg_cornermask,
+                                   $gdimg_cornermask_triple,
+                                   0,
+                                   $imgY - $radius_y,
+                                   $radius_x,
+                                   $radius_y * 3,
+                                   $radius_x,
+                                   $radius_y,
+                                   $radius_x * 2,
+                                   $radius_y * 2));
 
-                $this->_image->call('imageCopyResampled',
-                                     array($gdimg_cornermask,
-                                           $gdimg_cornermask_triple,
-                                           0,
-                                           0,
-                                           $radius_x,
-                                           $radius_y,
-                                           $radius_x,
-                                           $radius_y,
-                                           $radius_x * 2,
-                                           $radius_y * 2));
+        $this->_image->call('imageCopyResampled',
+                             array($gdimg_cornermask,
+                                   $gdimg_cornermask_triple,
+                                   $imgX - $radius_x,
+                                   $imgY - $radius_y,
+                                   $radius_x * 3,
+                                   $radius_y * 3,
+                                   $radius_x,
+                                   $radius_y,
+                                   $radius_x * 2,
+                                   $radius_y * 2));
 
-                $this->_image->call('imageCopyResampled',
-                                     array($gdimg_cornermask,
-                                           $gdimg_cornermask_triple,
-                                           0,
-                                           $imgY - $radius_y,
-                                           $radius_x,
-                                           $radius_y * 3,
-                                           $radius_x,
-                                           $radius_y,
-                                           $radius_x * 2,
-                                           $radius_y * 2));
+        $this->_image->call('imageCopyResampled',
+                             array($gdimg_cornermask,
+                                   $gdimg_cornermask_triple,
+                                   $imgX - $radius_x,
+                                   0,
+                                   $radius_x * 3,
+                                   $radius_y,
+                                   $radius_x,
+                                   $radius_y,
+                                   $radius_x * 2,
+                                   $radius_y * 2));
 
-                $this->_image->call('imageCopyResampled',
-                                     array($gdimg_cornermask,
-                                           $gdimg_cornermask_triple,
-                                           $imgX - $radius_x,
-                                           $imgY - $radius_y,
-                                           $radius_x * 3,
-                                           $radius_y * 3,
-                                           $radius_x,
-                                           $radius_y,
-                                           $radius_x * 2,
-                                           $radius_y * 2));
-
-                $this->_image->call('imageCopyResampled',
-                                     array($gdimg_cornermask,
-                                           $gdimg_cornermask_triple,
-                                           $imgX - $radius_x,
-                                           0,
-                                           $radius_x * 3,
-                                           $radius_y,
-                                           $radius_x,
-                                           $radius_y,
-                                           $radius_x * 2,
-                                           $radius_y * 2));
-
-                $result = $this->_image->applyMask($gdimg_cornermask);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
-                }
-                $this->_image->call('imageDestroy', array($gdimg_cornermask));
-                return true;
-            } else {
-                return $gdimg_cornermas; // PEAR_Error
-            }
-            $this->_image->call('imageDestroy',
-                                 array($gdimg_cornermask_triple));
-        } else {
-            return $gdimg_cornermas_triple; // PEAR_Error
-        }
+        $result = $this->_image->_applyMask($gdimg_cornermask);
+        $this->_image->call('imageDestroy', array($gdimg_cornermask));
+        $this->_image->call('imageDestroy', array($gdimg_cornermask_triple));
+        
+        return true;
     }
 
 }
\ No newline at end of file
index 098a503..ed3e5f6 100644 (file)
@@ -28,16 +28,8 @@ class Horde_Image_Effect_Gd_TextWatermark extends Horde_Image_Effect
      */
     public function apply()
     {
-        $color = $this->_image->call('imageColorClosest',
-                                      array($this->_image->_im, 255, 255, 255));
-        if (is_a($color, 'PEAR_Error')) {
-            return $color;
-        }
-        $shadow = $this->_image->call('imageColorClosest',
-                                       array($this->_image->_im, 0, 0, 0));
-        if (is_a($shadow, 'PEAR_Error')) {
-            return $shadow;
-        }
+        $color = $this->_image->call('imageColorClosest', array($this->_image->_im, 255, 255, 255));
+        $shadow = $this->_image->call('imageColorClosest', array($this->_image->_im, 0, 0, 0));
 
         // Shadow offset in pixels.
         $drop = 1;
@@ -50,13 +42,7 @@ class Horde_Image_Effect_Gd_TextWatermark extends Horde_Image_Effect
 
         $f = $this->_image->getFont($this->_params['fontsize']);
         $fontwidth = $this->_image->call('imageFontWidth', array($f));
-        if (is_a($fontwidth, 'PEAR_Error')) {
-            return $fontwidth;
-        }
         $fontheight = $this->_image->call('imageFontHeight', array($f));
-        if (is_a($fontheight, 'PEAR_Error')) {
-            return $fontheight;
-        }
 
         // So that shadow is not off the image with right align and bottom valign.
         $margin = floor($padding + $drop) / 2;
@@ -105,18 +91,12 @@ class Horde_Image_Effect_Gd_TextWatermark extends Horde_Image_Effect
 
         default:
             foreach ($lines as $line) {
-                if (is_a($result = $this->_image->call('imageString', array($this->_image->_im, $f, $margin + $drop, ($y + $drop), $line, $shadow)), 'PEAR_Error')) {
-                    return $result;
-                }
-                $result = $this->_image->call('imageString', array($this->_image->_im, $f, $margin, $y, $line, $color));
+                $this->_image->call('imageString', array($this->_image->_im, $f, $margin + $drop, ($y + $drop), $line, $shadow));
+                $this->_image->call('imageString', array($this->_image->_im, $f, $margin, $y, $line, $color));
                 $y += $fontheight;
             }
             break;
         }
-
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
     }
 
 }
\ No newline at end of file
index 8a29a1e..a302de3 100644 (file)
@@ -23,7 +23,7 @@ class Horde_Image_Effect_Gd_UnsharpMask extends Horde_Image_Effect
     /**
      * Apply the unsharp_mask effect.
      *
-     * @return mixed true | PEAR_Error
+     * @return mixed true
      */
     public function apply()
     {
index 98c541c..3591f31 100644 (file)
@@ -28,7 +28,7 @@ class Horde_Image_Effect_Im_DropShadow extends Horde_Image_Effect
     /**
      * Apply the effect.
      *
-     * @return mixed true | PEAR_Error
+     * @return mixed true
      */
     public function apply()
     {
index 62cedb5..ca0ddb3 100644 (file)
@@ -28,7 +28,7 @@ class Horde_Image_Effect_Imagick_DropShadow extends Horde_Image_Effect
     /**
      * Apply the effect.
      *
-     * @return mixed true | PEAR_Error
+     * @return boolean
      */
     public function apply()
     {
index 60f594d..078965b 100644 (file)
@@ -149,9 +149,7 @@ class Horde_Image_Effect_Imagick_PhotoStack extends Horde_Image_Effect
                     }
                 }
                 $result = $imgk->polaroidImage(new ImagickDraw(), $angle);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
-                }
+   
                  // Get the geometry of the image and remember the largest.
                 $geo = $imgk->getImageGeometry();
                 $length = max(
index 741f378..ab10125 100644 (file)
@@ -451,7 +451,7 @@ case 'testPolaroidstackBlueBG':
  *
  * @param array $params  Any additional parameters
  *
- * @return Horde_Image_Base object | PEAR_Error
+ * @return Horde_Image_Base The image object.
  */
 function getImageObject($params = array())
 {