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
This commit is contained in:
Loz Calver 2017-04-04 10:38:55 +01:00 committed by Sam Minnee
parent f101697f8e
commit ae0fe75fba
2 changed files with 28 additions and 2 deletions

View File

@ -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;

View File

@ -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;
}