Merge pull request #3591 from jedateach/issues/image-resize-fix

FIX: Image resizing breaks when one of the resized image dimensions is between 0 and 1
This commit is contained in:
Daniel Hensby 2014-10-30 14:46:40 +00:00
commit fbccd1af3f
2 changed files with 17 additions and 13 deletions

View File

@ -176,18 +176,20 @@ class GDBackend extends Object implements Image_Backend {
public function resize($width, $height) { public function resize($width, $height) {
if(!$this->gd) return; if(!$this->gd) return;
$width = round($width); if($width < 0 || $height < 0) throw new InvalidArgumentException("Image resizing dimensions cannot be negative");
$height = round($height); if(!$width && !$height) throw new InvalidArgumentException("No dimensions given when resizing image");
if(!$width) throw new InvalidArgumentException("Width not given when resizing image");
if(!$height) throw new InvalidArgumentException("Height not given when resizing image");
//use whole numbers, ensuring that size is at least 1x1
$width = max(1, round($width));
$height = max(1, round($height));
// Check that a resize is actually necessary. // Check that a resize is actually necessary.
if ($width == $this->width && $height == $this->height) { if ($width == $this->width && $height == $this->height) {
return $this; return $this;
} }
if(!$width && !$height) user_error("No dimensions given", E_USER_ERROR);
if(!$width) user_error("Width not given", E_USER_ERROR);
if(!$height) user_error("Height not given", E_USER_ERROR);
$newGD = imagecreatetruecolor($width, $height); $newGD = imagecreatetruecolor($width, $height);
// Preserves transparency between images // Preserves transparency between images

View File

@ -105,8 +105,14 @@ class ImagickBackend extends Imagick implements Image_Backend {
public function resize($width, $height) { public function resize($width, $height) {
if(!$this->valid()) return; if(!$this->valid()) return;
$width = round($width); if($width < 0 || $height < 0) throw new InvalidArgumentException("Image resizing dimensions cannot be negative");
$height = round($height); if(!$width && !$height) throw new InvalidArgumentException("No dimensions given when resizing image");
if(!$width) throw new InvalidArgumentException("Width not given when resizing image");
if(!$height) throw new InvalidArgumentException("Height not given when resizing image");
//use whole numbers, ensuring that size is at least 1x1
$width = max(1, round($width));
$height = max(1, round($height));
$geometry = $this->getImageGeometry(); $geometry = $this->getImageGeometry();
@ -115,10 +121,6 @@ class ImagickBackend extends Imagick implements Image_Backend {
return $this; return $this;
} }
if(!$width && !$height) user_error("No dimensions given", E_USER_ERROR);
if(!$width) user_error("Width not given", E_USER_ERROR);
if(!$height) user_error("Height not given", E_USER_ERROR);
$new = clone $this; $new = clone $this;
$new->resizeImage($width, $height, self::FILTER_LANCZOS, 1); $new->resizeImage($width, $height, self::FILTER_LANCZOS, 1);