Fix #6051 - image quality on scaled images
authorAlan Knowles <alan@roojs.com>
Wed, 2 Oct 2019 10:07:10 +0000 (18:07 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 2 Oct 2019 10:07:10 +0000 (18:07 +0800)
File/Convert.php
File/Convert/Solution.php

index 4596d67..66d00c6 100644 (file)
@@ -54,6 +54,7 @@ class File_Convert
     function convertExists($toMimetype, $x= 0, $y =0) 
     {
         
+        $fn = $this->fn;
         if ($toMimetype != $this->mimetype) {
             $action = $this->getConvMethods($this->mimetype, $toMimetype);
             
@@ -62,15 +63,16 @@ class File_Convert
                 return false;
             }
             $fn = $action->convertExists($this->fn, $x, $y);
-        } else {
-            $fn = $this->fn;
         }
+        
         if (!$fn) {
             return false;
         }
+        
         if (!preg_match('#^image/#', $toMimetype) || ( empty($x) && empty($y))) {
             return $fn;
         }
+        
         //echo "testing scale image";
         require_once 'File/Convert/Solution.php';
         $sc = new File_Convert_Solution('scaleImage', $toMimetype, $toMimetype);
@@ -105,7 +107,7 @@ class File_Convert
         if(empty($pg) || is_nan($pg * 1)){
             $pg = false;
         }
-        
+        $fn = $this->fn;
          //echo '<PRE>'; print_r(array('convert', func_get_args()));
         if (
                 $toMimetype != $this->mimetype ||
@@ -134,21 +136,8 @@ class File_Convert
             // let's assume that conversions can handle scaling??
             
             
-        } else {
-            $fn = $this->fn;
-        }
-//        if(!strpos($x, 'c')){
-//            print_r('inin?');
-//            print_r($x);
-//            print_r(' > ');
-//            print_r($y);exit;
-//            
-////            $size = explode('c', $x);
-//        }
-//        print_r(strpos($x, 'c'));
-//            print_r(' > ');
-//            print_r($y);exit;
-//        print_r($this->fn);exit;
+        }  
         if (preg_match('#^image/#', $toMimetype) && $toMimetype != 'image/gif' && ( !empty($x) || !empty($y))) {
             //var_dump(array($toMimetype));
             require_once 'File/Convert/Solution.php';
index 4e05268..36de05f 100644 (file)
@@ -999,6 +999,8 @@ class File_Convert_Solution
     }
     function scaleImage($fn, $x, $y) 
     {
+       
+        
         //  print_r(array('scaleimage', func_get_args()));
         if (empty($x) && empty($y)) {
             return false;
@@ -1007,7 +1009,7 @@ class File_Convert_Solution
         $target = $fn . '.'.$x.'x'.$y.'.' . $ext;
         
         
-        if (file_exists($target)  && filesize($target) && filemtime($target) > filemtime($fn)) {
+        if (empty($this->debug) && file_exists($target)  && filesize($target) && filemtime($target) > filemtime($fn)) {
             
             return $target;
         }
@@ -1065,11 +1067,15 @@ class File_Convert_Solution
          //var_dump($CONVERT);
          if ($CONVERT) {
             // note extend has to go after the resize.. so it does that first...
-            // changed to using 'sample' rather than resize -- it's alot faster? - not sure about quality though?
+            // changed to using 'sample' rather than resize
+            //-- it's alot faster? - not sure about quality though?
+            // 
+            $resize_method = filesize($fn) > 300000 ? '-sample' : '-scale';
+            
             $cmd = "{$CONVERT} " . $strip . " -colorspace sRGB -interlace none -density 800 -quality 90 ". 
-                 " -sample '{$scale}' ". $extent  . " '{$fn}' '{$targetName}'";
+                 " {$resize_method} '{$scale}' ". $extent  . " '{$fn}' '{$targetName}'";
              
-             $cmdres  = $this->exec($cmd);
+            $cmdres  = $this->exec($cmd);
             $this->exec($cmd);