Image scaling: Fixed a bug where (height > width) images would be scaled to the wrong dimensions (GD). Added PNG/GIF transparency support to GD image resizer. Added a cache bypass option to SpecialUpDownload.
authorDan Fuhry <dan@enanocms.org>
Wed, 25 Apr 2012 02:01:55 -0400
changeset 1360 570abc94bd7f
parent 1359 53c7e3cc7fb5
child 1361 26e80700ff1d
Image scaling: Fixed a bug where (height > width) images would be scaled to the wrong dimensions (GD). Added PNG/GIF transparency support to GD image resizer. Added a cache bypass option to SpecialUpDownload.
includes/functions.php
plugins/SpecialUpdownload.php
--- a/includes/functions.php	Mon Jan 16 09:23:20 2012 -0500
+++ b/includes/functions.php	Wed Apr 25 02:01:55 2012 -0400
@@ -4268,6 +4268,7 @@
 		{
 			die('SECURITY: ImageMagick path is screwy');
 		}
+		$magick_path = escapeshellcmd($magick_path);
 		$cmdline = "$magick_path $in_file_sh -resize \"{$width}x{$height}>\" $out_file_sh";
 		system($cmdline, $return);
 		if ( !file_exists($out_file) )
@@ -4291,7 +4292,7 @@
 		else if ( $ratio < 1 )
 		{
 			// orig. height is greater than width
-			$new_width = round( $height / $ratio );
+			$new_width = round( $height * $ratio );
 			$new_height = $height;
 		}
 		else if ( $ratio == 1 )
@@ -4313,6 +4314,13 @@
 		if ( !$oldimage )
 			throw new Exception('GD: Request to load input image file failed.');
 		
+		if ( $file_ext == 'png' || $file_ext == 'gif' )
+		{
+			imagecolortransparent($newimage, imagecolorallocatealpha($newimage, 0, 0, 0, 127));
+			imagealphablending($newimage, false);
+			imagesavealpha($newimage, true);
+		}
+		
 		// Perform scaling
 		imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
 		
--- a/plugins/SpecialUpdownload.php	Mon Jan 16 09:23:20 2012 -0500
+++ b/plugins/SpecialUpdownload.php	Wed Apr 25 02:01:55 2012 -0400
@@ -250,7 +250,7 @@
 			$extension = ".{$_GET['fmt']}";
 		
 		$cache_filename = ENANO_ROOT . "/cache/{$filename}-{$row['time_id']}-{$width}x{$height}$extension";
-		if ( file_exists($cache_filename) )
+		if ( file_exists($cache_filename) && !isset($_GET['cache_override']) )
 		{
 			$fname = $cache_filename;
 		}
@@ -281,7 +281,7 @@
 			}
 			if ( $allow_scale )
 			{
-				$result = scale_image($orig_fname, $fname, $width, $height);
+				$result = scale_image($orig_fname, $fname, $width, $height, isset($_GET['cache_override']));
 				if ( !$result )
 					$fname = $orig_fname;
 			}