ENHANCEMENT: Before preforming an image resize, make sure it's actually required.

This is better from an efficiency point of view and it also eliminates unessesary re-sampling (i.e. reduction in quailty).
This commit is contained in:
Simon Elvery 2012-03-26 14:21:14 +10:00
parent ac8a05f188
commit c9aa0e74b9

View File

@ -64,6 +64,11 @@ class GD extends Object {
$width = round($width);
$height = round($height);
// Check that a resize is actually necessary.
if ($width == $this->width && $height == $this->height) {
return $this;
}
$newGD = imagecreatetruecolor($width, $height);
// Preserves transparency between images
@ -125,6 +130,11 @@ class GD extends Object {
$width = round($width);
$height = round($height);
// Check that a resize is actually necessary.
if ($width == $this->width && $height == $this->height) {
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);
@ -299,6 +309,10 @@ class GD extends Object {
$width = round($width);
$height = round($height);
// Check that a resize is actually necessary.
if ($width == $this->width && $height == $this->height) {
return $this;
}
$newGD = imagecreatetruecolor($width, $height);