changeset 984:03b245ef3a47

Various fixes to previews generation.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 29 Nov 2014 16:04:21 +0200
parents 1e347288712d
children 31dc100c78d4
files faptool.php
diffstat 1 files changed, 30 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/faptool.php	Sat Nov 29 15:31:26 2014 +0200
+++ b/faptool.php	Sat Nov 29 16:04:21 2014 +0200
@@ -10,12 +10,12 @@
 
 
 
-function wtConvertImage($inFilename, $inFileType, $outFilename, $setDim, $setFormat, $setQuality, $thumb)
+function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv)
 {
   global $setPreviewPath;
   $isTemp = FALSE;
 
-  if ($inFileType == "gfx")
+  if ($useGfxConv)
   {
     // Oh great .. we need gfxconv here because Imagick handles ILBM like shit
     $tmpFilename = tempnam($setPreviewPath, "tmp");
@@ -35,9 +35,6 @@
   else
     $tmpFilename = $inFilename;
 
-  // convert -resize 640x480 -background black -gravity center -extent 640x480
-  //         -unsharp "0x0.75+0.75+0.008" lol.lbm -quality 95 test.jpg
-  
   // Create conversion entity
   $img = new Imagick($tmpFilename);
   if ($img === false)
@@ -46,15 +43,8 @@
     return FALSE;
   }
 
-  if ($setDim !== FALSE)
+  if ($outDim !== FALSE)
   {
-    if (($outDim = stGetSetting($setDim)) === FALSE ||
-        ($outFormat = stGetSetting($setFormat)) === FALSE ||
-        ($outQuality = stGetSetting($setQuality)) === FALSE)
-    {
-      die("Missing one of res/format/quality settings for '".$outFilename."'\n");
-    }
-
     // Get dimensions, setup background  
     $dim = $img->getImageGeometry();
 //    $img->setBackgroundColor(imagick::COLOR_BLACK);
@@ -84,6 +74,7 @@
   $img->stripImage();
   $img->writeImage($outFilename);
   $img->removeImage();
+  return TRUE;
 }
 
 
@@ -111,12 +102,13 @@
   $sduration = intval(stGetSetting("sampleDuration"));
   $schannels = intval(stGetSetting("sampleChannels"));
 
+  $optStr = "";
   foreach ($outOpts as $okey => $oval)
     $optStr .= $okey." ".$oval." ";
 
   return wtExec(
     "/usr/local/bin/avconv",
-    "-y -t ".intval($sduration)." ".
+    "-y -v 1 -t ".intval($sduration)." ".
     "-i ".escapeshellarg($inFilename).
     " ".$optStr." -ac ".$schannels.
     " -map_metadata -1 ".
@@ -157,9 +149,9 @@
     case EFILE_IMAGE:
       $res = wtConvertImage(
         $inFilename,
-        $edata["mime"],
         $outFilename,
-        FALSE, "PNG", 9, FALSE);
+        FALSE, "PNG", 9,
+        FALSE, ($edata["mime"] == "gfx"));
         break;
   }
 
@@ -202,6 +194,7 @@
   wtPurgeDir($path);
   wtMakeDir($path, 0700);
 
+  $cwd = getcwd();
   if (!is_dir($path) || chdir($path) === false)
   {
     echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n";
@@ -209,7 +202,10 @@
   }
 
   // Unpack archive
-  return wtExec($exe, $args);
+  $ret = wtExec($exe, $args);
+
+  chdir($cwd);
+  return $ret;
 }
 
 
@@ -305,10 +301,16 @@
         $fname = $path."/".$dentry;
         // check file type against entry's preview_type
         // if match, render / convert / cp to as source and exit loop.
-        if (is_file($fname) &&
-          ($mdata = stProbeFileInfo($fname, TRUE)) !== false &&
+        if ($dentry != "." && $dentry != "..")
+        {
+          if (is_dir($fname))
+            echo "XXX: ".$dentry." :: ".$fname."\n";
+          else
+          if (is_file($fname) &&
+            ($mdata = stProbeFileInfo($fname, TRUE)) !== false &&
             ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename, $force)) === true)
             break;
+        }
       }
 
       // Cleanup
@@ -367,17 +369,19 @@
     case EFILE_IMAGE:
       wtConvertImage(
         $inFilename,
-        "png",
         $pdata["files"]["image"]["file"],
-        "previewImageSize", "previewImageType",
-        "previewImageQuality", FALSE);
+        stGetSetting("previewImageSize"),
+        stGetSetting("previewImageType"),
+        stGetSetting("previewImageQuality"),
+        FALSE, FALSE);
 
       wtConvertImage(
         $inFilename,
-        "png",
         $pdata["files"]["thumb"]["file"],
-        "previewThumbSize", "previewThumbType",
-        "previewThumbQuality", TRUE);
+        stGetSetting("previewThumbSize"),
+        stGetSetting("previewThumbType"),
+        stGetSetting("previewThumbQuality"),
+        TRUE, FALSE);
       break;
   }
 
@@ -446,7 +450,7 @@
 //
 function wtExec($exe, $args, $expect = 0)
 {
-  echo "EXEC: ".$exe." ".$args."\n";
+  echo "EXEC: ".$exe." @ ".$args."\n";
   exec(escapeshellcmd($exe)." ".$args, $output, $code);
   if ($code !== $expect)
   {