From: Michael J. Rubinsky Date: Sun, 26 Sep 2010 19:44:42 +0000 (-0400) Subject: Experimental support for liquid image resizing in Horde_Image. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dcc5e1baa46fef8438a161593e04cdd0d6c2b920;p=horde.git Experimental support for liquid image resizing in Horde_Image. I think for Ansel, though, something based on a "center of edginess" technique might be better. --- diff --git a/framework/Image/lib/Horde/Image/Effect/Im/LiquidResize.php b/framework/Image/lib/Horde/Image/Effect/Im/LiquidResize.php new file mode 100644 index 000000000..0d77fc76c --- /dev/null +++ b/framework/Image/lib/Horde/Image/Effect/Im/LiquidResize.php @@ -0,0 +1,43 @@ + + * @package Horde_Image + */ +class Horde_Image_Effect_Im_LiquidResize extends Horde_Image_Effect +{ + /** + * Valid parameters: + *
+     *    width       - The target width
+     *    height      - the target height
+     *    ratio       - Keep aspect ratio
+     * 
+ * + * @var array + */ + protected $_params = array(); + + public function apply() + { + $this->_params = new Horde_Support_Array($this->_params); + + $resWidth = $this->_params->width * 2; + $resHeight = $this->_params->height * 2; + + $this->_image->addOperation("-size {$resWidth}x{$resHeight}"); + if ($this->_params->get('ratio', true)) { + $this->_image->addPostSrcOperation('-liquid-rescale' . " {$this->_params->width}x{$this->_params->height}"); + } else { + $this->_image->addPostSrcOperations('-liquid-rescale' . " {$this->_params->width}x{$this->_params->height}!"); + } + $this->_image->clearGeometry(); + } + +} \ No newline at end of file diff --git a/framework/Image/lib/Horde/Image/Effect/Imagick/LiquidResize.php b/framework/Image/lib/Horde/Image/Effect/Imagick/LiquidResize.php new file mode 100644 index 000000000..6227c3e30 --- /dev/null +++ b/framework/Image/lib/Horde/Image/Effect/Imagick/LiquidResize.php @@ -0,0 +1,41 @@ + + * @package Horde_Image + */ +class Horde_Image_Effect_Imagick_LiquidResize extends Horde_Image_Effect +{ + /** + * + * Valid parameters: + *
+     *    width       - The target width
+     *    height      - the target height
+     *    delta_x     - How much the seam may move on x axis (A value of 0
+     *                  causes the seam to be straight).
+     *   rigidity     - Introduces a bias for non-straight seams. Typically zero
+     * 
+ * + * @var array + */ + protected $_params = array(); + + public function apply() + { + $this->_params = new Horde_Support_Array($this->_params); + try { + $this->_image->imagick->liquidRescaleImage( + $this->_params->width, $this->_params->height, $this->_params->delta_x, $this->_params['rigidity']); + } catch (ImagickException $e) { + throw new Horde_Image_Exception($e); + } + } + +} \ No newline at end of file diff --git a/framework/Image/lib/Horde/Image/Im.php b/framework/Image/lib/Horde/Image/Im.php index 5d3575a57..563277b7a 100644 --- a/framework/Image/lib/Horde/Image/Im.php +++ b/framework/Image/lib/Horde/Image/Im.php @@ -298,7 +298,7 @@ class Horde_Image_Im extends Horde_Image_Base public function text($string, $x, $y, $font = '', $color = 'black', $direction = 0, $fontsize = 'small') { $string = addslashes('"' . $string . '"'); - $fontsize = self::getFontSize($fontsize); + $fontsize = Horde_Image::getFontSize($fontsize); $this->_postSrcOperations[] = "-fill $color " . (!empty($font) ? "-font $font" : '') . " -pointsize $fontsize -gravity northwest -draw \"text $x,$y $string\" -fill none"; } diff --git a/framework/Image/lib/Horde/Image/Imagick.php b/framework/Image/lib/Horde/Image/Imagick.php index 549bed30b..3df072fcb 100644 --- a/framework/Image/lib/Horde/Image/Imagick.php +++ b/framework/Image/lib/Horde/Image/Imagick.php @@ -312,7 +312,7 @@ class Horde_Image_Imagick extends Horde_Image_Base */ public function text($string, $x, $y, $font = '', $color = 'black', $direction = 0, $fontsize = 'small') { - $fontsize = self::getFontSize($fontsize); + $fontsize = Horde_Image::getFontSize($fontsize); $pixel = new ImagickPixel($color); $draw = new ImagickDraw(); $draw->setFillColor($pixel); diff --git a/framework/Image/package.xml b/framework/Image/package.xml index 046acfc4a..c890172f3 100644 --- a/framework/Image/package.xml +++ b/framework/Image/package.xml @@ -58,6 +58,7 @@ Initial Horde 4 package + @@ -68,6 +69,7 @@ Initial Horde 4 package + @@ -162,6 +164,7 @@ Initial Horde 4 package + @@ -170,6 +173,7 @@ Initial Horde 4 package + diff --git a/framework/Image/tests/im.php b/framework/Image/tests/im.php index ab101254e..20a3dd3de 100644 --- a/framework/Image/tests/im.php +++ b/framework/Image/tests/im.php @@ -8,7 +8,7 @@ * @package Horde_Image */ -require_once dirname(__FILE__) . '/../../../horde/lib/Application.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('authentication' => 'none')); // Putting these here so they don't interfere with timing/memory data when @@ -21,6 +21,12 @@ $handler = new Horde_Log_Handler_Stream(fopen('/tmp/imagetest.log','a+')); $logger = new Horde_Log_Logger($handler); switch ($test) { +case 'liquid': + $time = xdebug_time_index(); + $image = getImageObject(array('filename' => 'img4.jpg')); + $image->addEffect('LiquidResize', array('ratio' => true, 'width' => 612, 'height' => 340, 'delta_x' => 3, 'rigidity' => 0)); + $image->display(); + break; case 'multipage': $time = xdebug_time_index(); diff --git a/framework/Image/tests/img4.jpg b/framework/Image/tests/img4.jpg new file mode 100644 index 000000000..683358a02 Binary files /dev/null and b/framework/Image/tests/img4.jpg differ diff --git a/framework/Image/tests/runtest.php b/framework/Image/tests/runtest.php index e9cb656fb..169b8de08 100644 --- a/framework/Image/tests/runtest.php +++ b/framework/Image/tests/runtest.php @@ -3,7 +3,7 @@ * Test harness for generating the test images for Horde_Image tests */ -require_once dirname(__FILE__) . '/../../../horde/lib/Application.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('authentication' => 'none')); $allTests = array( @@ -31,9 +31,10 @@ $allTests = array( 'testRoundstackBlueBG' => 'Thumbnail stack, rounded corners on a blue background', 'testPolaroidstackTransparentBG' => 'Polaroid stack on a transparent background.', 'testPolaroidstackBlueBG' => 'Polaroid stack on a blue background', - //'testInitialStateAfterLoad' => 'Initial state after loading an existing image.', + 'testInitialStateAfterLoad' => 'Initial state after loading an existing image.', 'testResize' => 'Test resize method.', 'multipage' => 'Test Multipage tiffs', + 'liquid' => 'Test Seam Carving', ); ?> @@ -44,9 +45,10 @@ $allTests = array( $description) { - echo '' . - ''; + echo '' . + ''; } echo '
EffectImImagick
' . $description . '' . Horde::img('im.php?test=' . $name, '', '', '') . '' . Horde::img('im.php?test=' . $name . '&driver=Imagick', '', '', '') . '
' . $description . '
'; ?>