-
Notifications
You must be signed in to change notification settings - Fork 312
Open
Description
Hi,
we've found an use case where the image resizer is not working as expected.
In our case, this happens when using the resizeToWidth and resizeToHeight methods but the issue can be present in more places.
Inside the method a ratio is calculated and from that, the desired height/width is also calculated. It may happen that the calculated dimension is <0px which causes an error.
Example:
Original size: 600x2 px
Desired width is 100px max, so I use the resizeToWidth method.
public function resizeToWidth($width, $allow_enlarge = false)
{
$ratio = $width / $this->getSourceWidth(); // 0.16666666666
$height = (int) round($this->getSourceHeight() * $ratio); // 0.33333333332 -> 0
$this->resize($width, $height, $allow_enlarge);
return $this;
}Then, when I try to get the image's content using the getImageAsString method, it fails with:
imagecreatetruecolor(): Invalid image dimensions
I through about adding some minimum size in the resize method, but I'm not sure if it wouldn't break something else:
$this->dest_w = max($width, 1);
$this->dest_h = max($height, 1);Metadata
Metadata
Assignees
Labels
No labels