From a33d30317a9b84b942796dcd441c035f18a1a914 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 8 Jul 2010 10:51:56 -0400 Subject: [PATCH] get rid of remaining PEAR_Error in Horde_Image --- framework/Image/lib/Horde/Image/Base.php | 5 +- .../Image/lib/Horde/Image/Effect/Gd/DropShadow.php | 108 +++++++------- .../lib/Horde/Image/Effect/Gd/RoundCorners.php | 156 ++++++++++----------- .../lib/Horde/Image/Effect/Gd/TextWatermark.php | 28 +--- .../lib/Horde/Image/Effect/Gd/UnsharpMask.php | 2 +- .../Image/lib/Horde/Image/Effect/Im/DropShadow.php | 2 +- .../lib/Horde/Image/Effect/Imagick/DropShadow.php | 2 +- .../lib/Horde/Image/Effect/Imagick/PhotoStack.php | 4 +- framework/Image/tests/im.php | 2 +- 9 files changed, 129 insertions(+), 180 deletions(-) diff --git a/framework/Image/lib/Horde/Image/Base.php b/framework/Image/lib/Horde/Image/Base.php index 85bd7fb5a..1ea55e7a6 100644 --- a/framework/Image/lib/Horde/Image/Base.php +++ b/framework/Image/lib/Horde/Image/Base.php @@ -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) { diff --git a/framework/Image/lib/Horde/Image/Effect/Gd/DropShadow.php b/framework/Image/lib/Horde/Image/Effect/Gd/DropShadow.php index b18269caf..9850dc8a1 100644 --- a/framework/Image/lib/Horde/Image/Effect/Gd/DropShadow.php +++ b/framework/Image/lib/Horde/Image/Effect/Gd/DropShadow.php @@ -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; } diff --git a/framework/Image/lib/Horde/Image/Effect/Gd/RoundCorners.php b/framework/Image/lib/Horde/Image/Effect/Gd/RoundCorners.php index b4494d459..5687aa3d2 100644 --- a/framework/Image/lib/Horde/Image/Effect/Gd/RoundCorners.php +++ b/framework/Image/lib/Horde/Image/Effect/Gd/RoundCorners.php @@ -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 diff --git a/framework/Image/lib/Horde/Image/Effect/Gd/TextWatermark.php b/framework/Image/lib/Horde/Image/Effect/Gd/TextWatermark.php index 098a50363..ed3e5f6ef 100644 --- a/framework/Image/lib/Horde/Image/Effect/Gd/TextWatermark.php +++ b/framework/Image/lib/Horde/Image/Effect/Gd/TextWatermark.php @@ -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 diff --git a/framework/Image/lib/Horde/Image/Effect/Gd/UnsharpMask.php b/framework/Image/lib/Horde/Image/Effect/Gd/UnsharpMask.php index 8a29a1ef1..a302de338 100644 --- a/framework/Image/lib/Horde/Image/Effect/Gd/UnsharpMask.php +++ b/framework/Image/lib/Horde/Image/Effect/Gd/UnsharpMask.php @@ -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() { diff --git a/framework/Image/lib/Horde/Image/Effect/Im/DropShadow.php b/framework/Image/lib/Horde/Image/Effect/Im/DropShadow.php index 98c541c5c..3591f31da 100644 --- a/framework/Image/lib/Horde/Image/Effect/Im/DropShadow.php +++ b/framework/Image/lib/Horde/Image/Effect/Im/DropShadow.php @@ -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() { diff --git a/framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php b/framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php index 62cedb597..ca0ddb380 100644 --- a/framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php +++ b/framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php @@ -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() { diff --git a/framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php b/framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php index 60f594dab..078965b30 100644 --- a/framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php +++ b/framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php @@ -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( diff --git a/framework/Image/tests/im.php b/framework/Image/tests/im.php index 741f3788c..ab101254e 100644 --- a/framework/Image/tests/im.php +++ b/framework/Image/tests/im.php @@ -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()) { -- 2.11.0