Author: Tobias Schlitt Date: 2007-04-28 10:32:16 +0200 (Sat, 28 Apr 2007) New Revision: 4943
Log: - Implemented negative offsets for GD crop filter. Added: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_1 trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_2 trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_3 Modified: trunk/ImageConversion/src/handlers/gd.php trunk/ImageConversion/tests/filtersgd_test.php Modified: trunk/ImageConversion/src/handlers/gd.php =================================================================== --- trunk/ImageConversion/src/handlers/gd.php 2007-04-28 08:10:00 UTC (rev 4942) +++ trunk/ImageConversion/src/handlers/gd.php 2007-04-28 08:32:16 UTC (rev 4943) @@ -327,13 +327,13 @@ */ public function crop( $x, $y, $width, $height ) { - if ( !is_int( $x ) || $x < 0 ) + if ( !is_int( $x ) ) { - throw new ezcBaseValueException( 'x', $x, 'int >= 0' ); + throw new ezcBaseValueException( 'x', $x, 'int' ); } - if ( !is_int( $y ) || $y < 0 ) + if ( !is_int( $y ) ) { - throw new ezcBaseValueException( 'y', $y, 'int >= 0' ); + throw new ezcBaseValueException( 'y', $y, 'int' ); } if ( !is_int( $height ) ) { @@ -343,18 +343,21 @@ { throw new ezcBaseValueException( 'width', $width, 'int' ); } + + $oldResource = $this->getActiveResource(); + + $sourceWidth = imagesx( $oldResource ); + $sourceHeight = imagesy( $oldResource ); - $x = min( $x, $x + $width ); - $y = min( $y, $y + $height ); + $x = ( $x >= 0 ) ? $x : $sourceWidth + $x; + $y = ( $y >= 0 ) ? $y : $sourceHeight + $y; + + $x = abs( min( $x, $x + $width ) ); + $y = abs( min( $y, $y + $height ) ); $width = abs( $width ); $height = abs( $height ); - $oldResource = $this->getActiveResource(); - - $sourceWidth = imagesx( $oldResource ); - $sourceHeight = imagesy( $oldResource ); - if ( $x + $width > $sourceWidth ) { $width = $sourceWidth - $x; @@ -363,7 +366,7 @@ { $height = $sourceHeight - $y; } - + $this->performCrop( $x, $y, $width, $height ); } Added: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_1 =================================================================== (Binary files differ) Property changes on: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_1 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_2 =================================================================== (Binary files differ) Property changes on: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_2 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_3 =================================================================== (Binary files differ) Property changes on: trunk/ImageConversion/tests/data/compare/ezcImageConversionFiltersGdTest_testCropNegativeOffset_3 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/ImageConversion/tests/filtersgd_test.php =================================================================== --- trunk/ImageConversion/tests/filtersgd_test.php 2007-04-28 08:10:00 UTC (rev 4942) +++ trunk/ImageConversion/tests/filtersgd_test.php 2007-04-28 08:32:16 UTC (rev 4943) @@ -523,6 +523,42 @@ ); } + public function testCropNegativeOffset_1() + { + $this->handler->crop( -100, -100, 50, 50 ); + $this->handler->save( $this->imageReference, $this->getTempPath() ); + $this->assertImageSimilar( + $this->getReferencePath(), + $this->getTempPath(), + "Image not rendered as expected.", + ezcImageConversionTestCase::DEFAULT_SIMILARITY_GAP + ); + } + + public function testCropNegativeOffset_2() + { + $this->handler->crop( -50, -50, 50, 50 ); + $this->handler->save( $this->imageReference, $this->getTempPath() ); + $this->assertImageSimilar( + $this->getReferencePath(), + $this->getTempPath(), + "Image not rendered as expected.", + ezcImageConversionTestCase::DEFAULT_SIMILARITY_GAP + ); + } + + public function testCropNegativeOffset_3() + { + $this->handler->crop( -50, -50, -50, -50 ); + $this->handler->save( $this->imageReference, $this->getTempPath() ); + $this->assertImageSimilar( + $this->getReferencePath(), + $this->getTempPath(), + "Image not rendered as expected.", + ezcImageConversionTestCase::DEFAULT_SIMILARITY_GAP + ); + } + public function testColorspaceGrey() { $this->handler->colorspace( ezcImageColorspaceFilters::COLORSPACE_GREY ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components