From 46b01c4042b7a7f637394d7a62c3605eccd5dc6e Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 26 Jan 2011 17:09:45 +0000 Subject: [PATCH] make sure thumbnails have a max ratio of 5:1 --- ext/handle_pixel/main.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 081129d8..c426765e 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -76,25 +76,27 @@ class PixelFileHandler extends DataHandlerExtension { $q = $config->get_int("thumb_quality"); $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB - // convert to bitmap & back to strip metadata -- otherwise we - // can end up with 3KB of jpg data and 200KB of misc extra... - // "-limit memory $mem" broken? - // Windows is a special case if(in_array("OS", $_SERVER) && $_SERVER["OS"] == 'Windows_NT') { - $imageMagick = $config->get_string("thumb_convert_path"); - - // running the call with cmd.exe requires quoting for our paths - $stringFormat = '"%s" "%s[0]" -strip -thumbnail %ux%u jpg:"%s"'; - - // Concat the command altogether - $cmd = sprintf($stringFormat, $imageMagick, $inname, $w, $h, $outname); + $convert = $config->get_string("thumb_convert_path"); } else { - $cmd = "convert {$inname}[0] -strip -thumbnail {$w}x{$h} jpg:$outname"; + $convert = "convert"; } - // Execute IM's convert command, grab the output and return code it'll help debug it + // ffff imagemagic fails sometimes, not sure why + //$format = "'%s' '%s[0]' -format '%%[fx:w] %%[fx:h]' info:"; + //$cmd = sprintf($format, $convert, $inname); + //$size = shell_exec($cmd); + //$size = explode(" ", trim($size)); + $size = getimagesize($inname); + if($size[0] > $size[1]*5) $size[0] = $size[1]*5; + if($size[1] > $size[0]*5) $size[1] = $size[0]*5; + + // running the call with cmd.exe requires quoting for our paths + log_debug("handle_pixel", "cropping to {$size[0]}x{$size[1]} first"); + $format = '"%s" "%s[0]" -crop %ux%u +repage -flatten -strip -thumbnail %ux%u jpg:"%s"'; + $cmd = sprintf($format, $convert, $inname, $size[0], $size[1], $w, $h, $outname); exec($cmd, $output, $ret); log_debug('handle_pixel', "Generating thumnail with command `$cmd`, returns $ret"); @@ -140,6 +142,9 @@ class PixelFileHandler extends DataHandlerExtension { return $thumb; } else { + if($width > $height*5) $width = $height*5; + if($height > $width*5) $height = $width*5; + $image = imagecreatefromstring($this->read_file($tmpname)); $tsize = get_thumbnail_size($width, $height);