php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58895 cropThumbnailImage() doesn't crop to the specified size
Submitted: 2009-10-14 09:22 UTC Modified: 2010-02-28 07:12 UTC
From: laurent at 2mx dot fr Assigned:
Status: Closed Package: imagick (PECL)
PHP Version: 5.2.10 OS: Debian Leny
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: laurent at 2mx dot fr
New email:
PHP Version: OS:

 

 [2009-10-14 09:22 UTC] laurent at 2mx dot fr
Description:
------------
imagick::cropThumbnailImage() doesn't resize and crop to the specified size

I'm using the sample image "sunset" provided with windows XP (in My Images) for this code.

When using imagick::cropThumbnailImage(170, 120) the generated image is 160 x 120

Note this is not the case with all the images i have tested.
If I calculate the crop dimensions with php and use imagick::resizeImage() and imagick::cropImage() I'm getting an image of image is 170 x 120

Thanks


Reproduce code:
---------------
$crop1 = new imagick( 'Imagick/sunset.jpg' );
$crop1->cropThumbnailImage( 170, 120 );
$crop1->writeImage( "Imagick/crop_sunset.jpg" );

$crop2 = new imagick( 'Imagick/sunset.jpg' );
$width=170;
$height=120;
//offset calculation
$srcWidth = $crop2->getImageWidth ();
$srcHeight = $crop2->getImageHeight ();
$scaleRatio = max ( $width / $srcWidth, $height / $srcHeight );
$scaleWidth = round ( $srcWidth * $scaleRatio );
$scaleHeight = round ( $srcHeight * $scaleRatio );
$cropOffsetX = ($scaleWidth > $width) ? round ( ($scaleWidth - $width) / 2 ) : 0;
$cropOffsetY = ($scaleHeight > $height) ? round ( ($scaleHeight - $height) / 2 ) : 0;
$cropDimentions = array ($width, $height );
$cropPosition = array ($cropOffsetX, $cropOffsetY );
//resize and crop
$crop2->resizeImage ( $scaleWidth, $scaleHeight, imagick::FILTER_UNDEFINED, 1, true );
$crop2->cropImage ( $cropDimentions [0], $cropDimentions [1], $cropPosition [0], $cropPosition [1] );
$crop2->writeImage( "Imagick/crop2_sunset.jpg" );

Expected result:
----------------
crop1 ouput an image of size 160 x 120

crop2 output an image of size 170 x 120


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-14 09:38 UTC] mkoppanen@php.net
Hey,

I working on Imagick 3.x version and the cropThumbnailImage will go through some changes soon. As it is the behavior is quite undefined.
 [2010-02-28 07:12 UTC] mkoppanen@php.net
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pecl.php.net/get/imagick


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC