Skip to content
This repository
Browse code

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 authored March 26, 2012

Showing 1 changed file with 14 additions and 0 deletions. Show diff stats Hide diff stats

  1. 14  filesystem/GD.php
14  filesystem/GD.php
@@ -64,6 +64,11 @@ function croppedResize($width, $height) {
64 64
 		$width = round($width);
65 65
 		$height = round($height);
66 66
 		
  67
+		// Check that a resize is actually necessary.
  68
+		if ($width == $this->width && $height == $this->height) {
  69
+			return $this;
  70
+		}
  71
+		
67 72
 		$newGD = imagecreatetruecolor($width, $height);
68 73
 		
69 74
 		// Preserves transparency between images
@@ -125,6 +130,11 @@ function resize($width, $height) {
125 130
 		$width = round($width);
126 131
 		$height = round($height);
127 132
 		
  133
+		// Check that a resize is actually necessary.
  134
+		if ($width == $this->width && $height == $this->height) {
  135
+			return $this;
  136
+		}
  137
+		
128 138
 		if(!$width && !$height) user_error("No dimensions given", E_USER_ERROR);
129 139
 		if(!$width) user_error("Width not given", E_USER_ERROR);
130 140
 		if(!$height) user_error("Height not given", E_USER_ERROR);
@@ -299,6 +309,10 @@ function paddedResize($width, $height, $backgroundColor = "FFFFFF") {
299 309
 		$width = round($width);
300 310
 		$height = round($height);
301 311
 		
  312
+		// Check that a resize is actually necessary.
  313
+		if ($width == $this->width && $height == $this->height) {
  314
+			return $this;
  315
+		}
302 316
 		
303 317
 		$newGD = imagecreatetruecolor($width, $height);
304 318
 		

0 notes on commit c9aa0e7

Please sign in to comment.
Something went wrong with that request. Please try again.