PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Images » Image_Transform » Bug #2360

wrong implementation of fit() in CVS

Details

Submitted2004-09-20 00:59 UTC
Fromnorbert_m at php dot net
Assignedjausions
StatusClosed
PackageImage_Transform
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-09-20 00:59 UTC] norbert_m at php dot net

Description:
------------
The actual fit method doesn't work as expected and described in the code comments:

"If the image is bigger than the box specified by $width and $height, it will be scaled down to fit inside of it."

This happens because the following snippet is wrong (function fit(...):
return ($this->img_y <= $height)
? $this->scaleByX($width)
: $this->scaleByY($height);

Reproduce code:
---------------
include_once 'Image/Transform.php';
$im = Image_Transform::factory('GD');
if (PEAR::isError($im)) {
return $im;
}
$im->load($this->__picdir . $id . '.jpg');
$im->fit(470, 470);
$im->save($this->__thumbdir . $id . '.jpg', 'jpeg', 80);

Expected result:
----------------
Image resized to a max of 470 pixels in length in either directions (i.e. the max length (width/height) of the image is 470px)

Actual result:
--------------
Image may get bigger than specified in the function params.

The above snippet should look like:

if (($this->img_x / $width) > ($this->img_y / $height)) {
return $this->scaleByX($width);
} else {
return $this->scaleByY($height);
}