Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT: Before preforming an image resize, make sure it's actual…

…ly required.

This is better from an efficiency point of view and it also eliminates unessesary re-sampling (i.e. reduction in quailty).
  • Loading branch information...
commit c9aa0e74b961be30588437f7be4be315eb47a06f 1 parent ac8a05f
Simon Elvery drzax authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 filesystem/GD.php
14 filesystem/GD.php
View
@@ -64,6 +64,11 @@ function croppedResize($width, $height) {
$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 @@ function resize($width, $height) {
$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 @@ function paddedResize($width, $height, $backgroundColor = "FFFFFF") {
$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);
Please sign in to comment.
Something went wrong with that request. Please try again.