image/jpg hacky support
authorAlan <alan@roojs.com>
Tue, 28 Jun 2022 05:44:20 +0000 (13:44 +0800)
committerAlan <alan@roojs.com>
Tue, 28 Jun 2022 05:44:20 +0000 (13:44 +0800)
File/Convert.php
File/Convert/Solution.php
File/Convert/Solution/scaleimage.php
File/MimeType.php

index b51cbb0..a716761 100644 (file)
@@ -86,7 +86,7 @@ class File_Convert
             $fn = $action->convertExists($this->fn, $x, $y);
             
         }
-        
+       
         if (!$fn) {
             return false;
         }
@@ -127,9 +127,12 @@ class File_Convert
     function convert($toMimetype, $x= 0, $y =0, $pg=false) 
     {
         //print_R(func_get_args());
-        $pg = (int) $pg;
+        if ($toMimetype == 'image/jpg') {
+            $toMimetype = 'image/jpeg';
+        }
         
-        if(empty($pg) || is_nan($pg * 1)){
+        $pg = (int) $pg;
+         if(empty($pg) || is_nan($pg * 1)){
             $pg = false;
         }
         $fn = $this->fn;
@@ -162,17 +165,18 @@ class File_Convert
             
             
         }  
+             
+
         if (preg_match('#^image/#', $toMimetype) && $toMimetype != 'image/gif' && ( !empty($x) || !empty($y))) {
             //var_dump(array($toMimetype));
+               
             require_once 'File/Convert/Solution.php';
             $scf = (strpos($x, 'c')  !== false ? 'scaleimagec' : 'scaleimage' );
             require_once 'File/Convert/Solution/'. $scf . '.php';
             $scls = 'File_Convert_Solution_' . $scf;
                 
-                
             $sc = new $scls($toMimetype, $toMimetype);
-            $sc->debug= $this->debug;
+            $sc->debug=  $this->debug;
             $this->solutions[] = $sc;
             $x  = str_replace('c', 'x', $x);
             
@@ -184,8 +188,9 @@ class File_Convert
             $x = strlen($x) ? (int) $x : '';
             $y = strlen($y) ? (int) $y : '';
             //print_r($x); print_r(' > '); print_r($y);exit;
+            
             $fn = $sc->runconvert($fn,  $x, $y, $pg);
-             
+          
         }
 //        print_r($this->target);
         $this->target = $fn;
index fdcd026..07c7112 100644 (file)
@@ -73,7 +73,8 @@ class File_Convert_Solution
             return false;
         }
         if (!$this->ext) {
-            return false;
+            die("missing mimetype");
+             
         }
         
         $this->debug("runconvert : {$fn}, {$x}, {$y}, {$pg}");
index ec5bb7b..8bcd671 100644 (file)
@@ -23,9 +23,9 @@ class File_Convert_Solution_scaleimage extends File_Convert_Solution
     function convert($fn,$x,$y,$pg) 
     {
         
-        //  print_r(array('scaleimage', func_get_args()));
-        clearstatcache();
+          clearstatcache();
         if (!file_exists($fn) || (empty($x) && empty($y))) {
+            
             return false;
         }
         $ext = $this->ext;
@@ -33,7 +33,7 @@ class File_Convert_Solution_scaleimage extends File_Convert_Solution
         
         $this->debug("COVERT: FE:" . (file_exists($target) ? 1: 0) );
         $this->debug("COVERT: FS:" . (file_exists($target) ?  (filemtime($target) . '>' .  filemtime($fn)) : 'n/a'));
-       
         if ($this->debug < 2 && file_exists($target)  && filesize($target) && filemtime($target) > filemtime($fn)) {
             $this->debug("SCALEIMAGE - image exists $target");
             return $target;
@@ -48,7 +48,7 @@ class File_Convert_Solution_scaleimage extends File_Convert_Solution
         //echo "GOT TARGET"  . $target;
         
         list($width, $height) = @getimagesize($fn);
-        
+       
         $extent = '';
         switch (true) { // what about fit/pad etc...
             
@@ -95,11 +95,11 @@ class File_Convert_Solution_scaleimage extends File_Convert_Solution
                 $extent ="-extent '{$x}x{$y}>' -gravity center -background white {$define}";
                 break;
         }
+        
         require_once 'System.php';
         $CONVERT = System::which("convert");
         
-         //var_dump($CONVERT);
-         if ($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?
@@ -109,8 +109,7 @@ class File_Convert_Solution_scaleimage extends File_Convert_Solution
             $cmd = "{$CONVERT} " . $strip . " -colorspace sRGB -interlace none -density 800 -quality 90 ". 
                  (strlen($scale) ?  " {$resize_method} '{$scale}' " : '' ).
                  $extent  . " '{$fn}' '{$targetName}'";
-            //var_dump($cmd);exit;
-            $cmdres  = $this->exec($cmd);
+             $cmdres  = $this->exec($cmd);
             $this->exec($cmd);
             
             
index 2711e8d..cfeb642 100644 (file)
@@ -106,6 +106,9 @@ class File_MimeType
                 array( 'video/vnd.mpegurl', array('m4u')),
                 array( 'video/x-flv', array('flv')),
                 array( 'video/ogg', array('ogv')),
+                
+                
+            
             
             
             ), 
@@ -140,7 +143,15 @@ class File_MimeType
     function toExt($mtype) 
     {
         $mtype = strtolower($mtype);
+        switch($mtype) {
+            case 'image/jpg':
+                $mtype = 'image/jpeg';
+                break;
+            // any others.?
+        }
+        
         $mtl = $GLOBALS['File_MimeType'];
+         
         foreach($mtl as $mtd) {
             if ($mtd[0] == $mtype) {
                 return $mtd[1][0];