# HG changeset patch # User Matti Hamalainen # Date 1417248800 -7200 # Node ID 26ae3f21a3bbced1c9a008c2f8d45b402f55df86 # Parent c71afc1a3a855e15b4f3ea1a35cf6de7689705a4 Moar work on previews. diff -r c71afc1a3a85 -r 26ae3f21a3bb faptool.php --- a/faptool.php Sat Nov 29 08:38:34 2014 +0200 +++ b/faptool.php Sat Nov 29 10:13:20 2014 +0200 @@ -56,7 +56,7 @@ // Get dimensions, setup background $dim = $img->getImageGeometry(); - $img->setBackgroundColor(imagick::COLOR_BLACK); +// $img->setBackgroundColor(imagick::COLOR_BLACK); $img->setGravity(imagick::GRAVITY_CENTER); // Act based on image size vs. desired size and $thumb mode @@ -64,7 +64,7 @@ { // Image is larger $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1); - $img->setExtent($outDim[0], $outDim[1]); + $img->setImageExtent($outDim[0], $outDim[1]); $img->normalizeImage(); $img->unsharpMaskImage(0, 0.5, 1, 0.05); } @@ -73,7 +73,7 @@ { // Image is smaller than requested dimension(s)? $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_POINT, 1); - $img->setExtent($outDim[0], $outDim[1]); + $img->setImageExtent($outDim[0], $outDim[1]); } } @@ -123,24 +123,34 @@ } -function wtRenderConvertEntryToSource($inFilename, $edata, $entryFilename, &$outData, &$outFilename) +function wtEntryToSource($compo, $inFilename, $edata, $entryFilename, &$outData, &$outFilename) { // Does compo preview type match this file class? if ($edata["class"] != $compo["preview_type"]) return FALSE; - $outFilename = stReplaceFileExt($entryFilename, "_preview.".$edata["fext"]); + switch ($edata["class"]) + { + case EFILE_AUDIO: $fext = "wav"; break; + case EFILE_IMAGE: $fext = "png"; break; + default: + return FALSE; + } + + $outFilename = stReplaceFileExt($entryFilename, "_preview.".$fext); if (file_exists($outFilename) && filemtime($outFilename) >= filemtime($entryFilename)) - return FALSE; + return TRUE; - echo "CHECKING: ".$inFilename." / ".$edata["id"]."\n"; + printf("GENERATING: %s -> %s\n", $inFilename, $outFilename); + switch ($edata["class"]) { case EFILE_AUDIO: if ($edata["mime"] == "audio/x-mod") $res = wtRenderSample($inFilename, $outFilename); else - $res = wtConvertSample($inFilename, $outFilename, array()); + $res = wtConvertSample($inFilename, $outFilename, + array("-f" => "wav")); break; case EFILE_IMAGE: @@ -150,9 +160,6 @@ $outFilename, FALSE, "PNG", 9, FALSE); break; - - default: - return FALSE; } return $res; @@ -299,7 +306,7 @@ // if match, render / convert / cp to as source and exit loop. if (is_file($fname) && ($mdata = stProbeFileInfo($fname, TRUE)) !== false && - ($found = wtRenderConvertEntryToSource($fname, $mdata, $filename, $pdata, $outFilename)) === true) + ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename)) === true) break; } @@ -311,43 +318,49 @@ if ($edata["class"] == $compo["preview_type"]) { // Single file - $found = wtRenderConvertEntryToSource($filename, $edata, $filename, $pdata, $outFilename); + $found = wtEntryToSource($compo, $filename, $edata, $filename, $pdata, $outFilename); } + + printf("X: %d, %d\n", $edata["class"], $compo["preview_type"]); + print_r($edata); if (!$found) { echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n"; return FALSE; } + + $inFilename = $outFilename; } + else + $inFilename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $pdata["file"]["filename"])); // Either we now have a sourcefile or generated file - switch ($outData["class"]) + switch ($compo["preview_type"]) { case EFILE_AUDIO: foreach (stGetSetting("sampleTypes") as $stype => $sopts) { - if (!isset($fileTypeData[$stype])) - die("Internal error: Sample type ".$stype." in sampleTypes in mconfig.inc.php, but not defined in file type data.\n"); - - $filename = $pdata["files"][$sdata]["file"]; - wtConvertSample( $inFilename, - stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), + $pdata["files"][$stype]["file"], $sopts ); } break; - + case EFILE_IMAGE: - wtConvertImage($inFilename, - stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), + wtConvertImage( + $inFilename, + "png", + $pdata["files"]["image"]["file"], "previewImageSize", "previewImageType", "previewImageQuality", FALSE); - wtConvertImage($inFilename, - stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $setThumbPath, $filename)), + wtConvertImage( + $inFilename, + "png", + $pdata["files"]["thumb"]["file"], "previewThumbSize", "previewThumbType", "previewThumbQuality", TRUE); break; @@ -444,7 +457,7 @@ { if ($path != "" && $path !== false && file_exists($path) && is_dir($path)) { - echo "PURGING: ".$path."\n"; +// echo "PURGING: ".$path."\n"; foreach (scandir($path) as $file) if ($file !== "." && $file !== "..") { @@ -452,10 +465,7 @@ if (is_dir($sub)) wtPurgeDir($sub); else - { - echo " - ".$sub."\n"; unlink($sub); - } } rmdir($path); } diff -r c71afc1a3a85 -r 26ae3f21a3bb msite.inc.php --- a/msite.inc.php Sat Nov 29 08:38:34 2014 +0200 +++ b/msite.inc.php Sat Nov 29 10:13:20 2014 +0200 @@ -955,6 +955,7 @@ $pdata["type"] = $fileTypeData[$efile["filetype"]]["type"]; } else + if ($entry["file_id"] == 0) $pdata["valid"] = $efile = false; switch ($pdata["type"]) @@ -983,16 +984,13 @@ return FALSE; } - if ($efile !== false) + foreach ($pdata["files"] as $pkey => $pfile) { - foreach ($pdata["files"] as $pkey => $pfile) - { - if ($pfile["exists"]) - $pdata["exists"]++; + if ($pfile["exists"]) + $pdata["exists"]++; - if (!$pfile["exists"] || $pfile["mtime"] < $efile["utime"]) - $pdata["valid"] = FALSE; - } + if (!$pfile["exists"])// + $pdata["valid"] = FALSE; } return TRUE;