From c9aa0e74b961be30588437f7be4be315eb47a06f Mon Sep 17 00:00:00 2001 From: Simon Elvery Date: Mon, 26 Mar 2012 14:21:14 +1000 Subject: [PATCH] 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). --- filesystem/GD.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/filesystem/GD.php b/filesystem/GD.php index 667265096..16eccff93 100644 --- a/filesystem/GD.php +++ b/filesystem/GD.php @@ -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);