From ae0fe75fba35918735656ea82cab2e7584b27f07 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Tue, 4 Apr 2017 10:38:55 +0100 Subject: [PATCH] Fix non-numeric warnings in GDBackend/ImagickBackend intval() will convert non-numeric values to 0, and Image_Backend::resize() will subsequently raise the appropriate exception --- filesystem/GD.php | 11 +++++++++++ filesystem/ImagickBackend.php | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/filesystem/GD.php b/filesystem/GD.php index 7cd4c3aad..89d2dfc86 100644 --- a/filesystem/GD.php +++ b/filesystem/GD.php @@ -220,6 +220,8 @@ class GDBackend extends Object implements Image_Backend { * @todo This method isn't very efficent */ public function fittedResize($width, $height) { + $width = intval($width); + $height = intval($height); $gd = $this->resizeByHeight($height); if($gd->width > $width) $gd = $gd->resizeByWidth($width); return $gd; @@ -354,6 +356,11 @@ class GDBackend extends Object implements Image_Backend { */ public function crop($top, $left, $width, $height) { + $top = intval($top); + $left = intval($left); + $width = intval($width); + $height = intval($height); + $newGD = imagecreatetruecolor($width, $height); // Preserve alpha channel between images @@ -390,6 +397,7 @@ class GDBackend extends Object implements Image_Backend { * Resize an image by width. Preserves aspect ratio. */ public function resizeByWidth( $width ) { + $width = intval($width); $heightScale = $width / $this->width; return $this->resize( $width, $heightScale * $this->height ); } @@ -398,6 +406,7 @@ class GDBackend extends Object implements Image_Backend { * Resize an image by height. Preserves aspect ratio */ public function resizeByHeight( $height ) { + $height = intval($height); $scale = $height / $this->height; return $this->resize( $scale * $this->width, $height ); } @@ -407,6 +416,8 @@ class GDBackend extends Object implements Image_Backend { * and maxHeight. Passing useAsMinimum will make the smaller dimension equal to the maximum corresponding dimension */ public function resizeRatio( $maxWidth, $maxHeight, $useAsMinimum = false ) { + $maxWidth = intval($maxWidth); + $maxHeight = intval($maxHeight); $widthRatio = $maxWidth / $this->width; $heightRatio = $maxHeight / $this->height; diff --git a/filesystem/ImagickBackend.php b/filesystem/ImagickBackend.php index 0399af1e6..901315994 100644 --- a/filesystem/ImagickBackend.php +++ b/filesystem/ImagickBackend.php @@ -148,6 +148,9 @@ class ImagickBackend extends Imagick implements Image_Backend { public function resizeRatio($maxWidth, $maxHeight, $useAsMinimum = false) { if(!$this->valid()) return; + $maxWidth = intval($maxWidth); + $maxHeight = intval($maxHeight); + $geometry = $this->getImageGeometry(); $widthRatio = $maxWidth / $geometry["width"]; @@ -168,6 +171,8 @@ class ImagickBackend extends Imagick implements Image_Backend { public function resizeByWidth($width) { if(!$this->valid()) return; + $width = intval($width); + $geometry = $this->getImageGeometry(); $heightScale = $width / $geometry["width"]; @@ -183,6 +188,8 @@ class ImagickBackend extends Imagick implements Image_Backend { public function resizeByHeight($height) { if(!$this->valid()) return; + $height = intval($height); + $geometry = $this->getImageGeometry(); $scale = $height / $geometry["height"]; @@ -198,6 +205,9 @@ class ImagickBackend extends Imagick implements Image_Backend { * @return Image_Backend */ public function paddedResize($width, $height, $backgroundColor = "FFFFFF", $transparencyPercent = 0) { + $width = intval($width); + $height = intval($height); + //keep the % within bounds of 0-100 $transparencyPercent = min(100, max(0, $transparencyPercent)); $new = $this->resizeRatio($width, $height); @@ -265,7 +275,7 @@ class ImagickBackend extends Imagick implements Image_Backend { $new->ThumbnailImage($width,$height,true); return $new; } - + /** * Crop's part of image. * @param int $top y position of left upper corner of crop rectangle @@ -275,9 +285,14 @@ class ImagickBackend extends Imagick implements Image_Backend { * @return Image_Backend */ public function crop($top, $left, $width, $height) { + $top = intval($top); + $left = intval($left); + $width = intval($width); + $height = intval($height); + $new = clone $this; $new->cropImage($width, $height, $left, $top); - + return $new; }