From fd9d3278078df67aab6cee0c2b7b43a27f206983 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 19 Mar 2013 17:31:06 +0000 Subject: avoid creating an intermediate crop image when the final image will match a resize --- inc/media.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inc/media.php b/inc/media.php index 2268ad877..654d31cb4 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1828,6 +1828,13 @@ function media_crop_image($file, $ext, $w, $h=0){ // calculate crop size $fr = $info[0]/$info[1]; $tr = $w/$h; + + // check if the crop can be handled completely by resize, + // i.e. the specified width & height match the aspect ratio of the source image + if ($w == round($h*$fr)) { + return media_resize_image($file, $ext, $w); + } + if($tr >= 1){ if($tr > $fr){ $cw = $info[0]; -- cgit v1.2.3 From f0b65004f2ff928562c2ffdfa31b4d1e4cff3ab7 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 22 Mar 2013 19:37:02 +0000 Subject: don't resize images when resize dimensions match native image dimensions --- inc/media.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/media.php b/inc/media.php index 654d31cb4..fc4ad1d67 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1795,6 +1795,9 @@ function media_resize_image($file, $ext, $w, $h=0){ // we wont scale up to infinity if($w > 2000 || $h > 2000) return $file; + // resize necessary? - (w,h) = native dimensions + if(($w == $info[0]) && ($h == $info[1])) return $file; + //cache $local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext); $mtime = @filemtime($local); // 0 if not exists -- cgit v1.2.3