Thumb rewrite and move to helper
This commit is contained in:
120
helper.php
120
helper.php
@@ -16,6 +16,9 @@ $pathname = $argv[3];
|
||||
$bpath = $argv[4];
|
||||
$mytime = $argv[5];
|
||||
|
||||
$tmpdir = "/tmp/yuba/".$mytime;
|
||||
if (!is_dir($tmpdir)) { mkdir($tmpdir,0777,true); }
|
||||
|
||||
$file = pathinfo($pathname, PATHINFO_BASENAME);
|
||||
$ext = pathinfo($pathname, PATHINFO_EXTENSION);
|
||||
|
||||
@@ -45,7 +48,7 @@ switch ($mode) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tfile = "/tmp/Yuba/".$mytime."/".substr($fid,0,3)."/".$file.".png";
|
||||
$tfile = $tmpdir."/".substr($fid,0,2)."/".$file.".png";
|
||||
if (!is_dir(dirname($tfile))) { @mkdir(dirname($tfile)); }
|
||||
// workaround for qlmanage naming convention
|
||||
|
||||
@@ -82,10 +85,11 @@ switch ($mode) {
|
||||
|
||||
// > code for custom qlgenerator bindings goes here <
|
||||
|
||||
$cmd = "qlmanage -ti -f ".floor($p['icon_size']/128)." -o ".basename($tfile)." ".$shellpath;
|
||||
//$cmd = "qlmanage -ti -s ".$p['icon_size']." -o ".dirname($tfile)." ".$shellpath;
|
||||
$cmd = "qlmanage -ti -f ".floor($p['icon_size']/128)." -o ".dirname($tfile)." ".$shellpath;
|
||||
|
||||
}
|
||||
|
||||
|
||||
shell_exec($cmd);
|
||||
|
||||
if (@filesize($tfile)) {
|
||||
@@ -106,17 +110,18 @@ switch ($mode) {
|
||||
|
||||
$dfile = $bpath."/icons/".substr($hash, 0, 2)."/".$hash.".png";
|
||||
if (!is_dir(dirname($dfile))) { @mkdir(dirname($dfile)); }
|
||||
|
||||
|
||||
echo " ->use";
|
||||
|
||||
if ($tool == "qltool") {
|
||||
// qltool makes 2x icons for some reason
|
||||
|
||||
echo " ->use";
|
||||
|
||||
//shell_exec("sips -z ".$p['icon_size']." ".$p['icon_size']." ".$tfile." --out ".$dfile);
|
||||
shell_exec($bin_convert." ".escapeshellarg($tfile)." -scale 50% -strip -define png:compression-level=9 ".$dfile);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
//rename($tfile,$dfile);
|
||||
shell_exec($bin_convert." ".escapeshellarg($tfile)." -strip -define png:compression-level=9 ".$dfile);
|
||||
|
||||
}
|
||||
@@ -135,6 +140,8 @@ switch ($mode) {
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
echo " ->db";
|
||||
|
||||
break;
|
||||
|
||||
case "thumbs":
|
||||
@@ -149,6 +156,105 @@ switch ($mode) {
|
||||
6616,
|
||||
17393 );
|
||||
|
||||
$tfile = $tmpdir."/".substr($fid,0,2)."/".$fid.".jpg";
|
||||
$tpfile = $tmpdir."/".substr($fid,0,2)."/".$file.".png"; // workaround for qlmanage naming convention
|
||||
if (!is_dir(dirname($tfile))) { @mkdir(dirname($tfile)); }
|
||||
|
||||
if (in_array($ext, $p['t_skip'])) {
|
||||
// file extension is in the skip list
|
||||
echo " ->t_skip";
|
||||
break;
|
||||
}
|
||||
|
||||
if ($p['thumbs'] == 1 && file_exists($tfile)) {
|
||||
// if this is not a rebuild, first check for an existing thumb file (faster)
|
||||
echo " ->skip_fast";
|
||||
break;
|
||||
}
|
||||
|
||||
$rowid = @$dbp->query("SELECT rowid FROM thumbs WHERE fid='".$fid."'")->fetch()['rowid'];
|
||||
// check for existing thumb generation attempt
|
||||
|
||||
if (!$rowid) {
|
||||
// no prior attempt
|
||||
|
||||
$stmt = $dbp->prepare("INSERT INTO thumbs VALUES (:fid, :created, :relative_path, :width, :height, :tool)");
|
||||
echo " ->generate";
|
||||
|
||||
} elseif ($rowid && $p['thumbs'] == 2) {
|
||||
// prior attempt but rebuild mode
|
||||
|
||||
$stmt = $dbp->prepare("UPDATE thumbs SET fid = :fid, created = :created, relative_path = :relative_path, width = :width, height = :height, tool = :tool WHERE rowid = ".$rowid);
|
||||
echo " ->rebuild";
|
||||
|
||||
} else {
|
||||
// prior attempt
|
||||
|
||||
echo " ->skip";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$cmd['sips'] = "sips -s format jpeg -s formatOptions 80 --resampleHeightWidthMax ".$p['thumb_size']." ".$shellpath." --out ".$tfile; // add ?? "-d profile --deleteColorManagementProperties"
|
||||
$cmd['vips'] = $bin_vips." ".$shellpath." -o ".$tfile."[Q=90,optimize_coding] --size=".$p['thumb_size'];
|
||||
|
||||
$cmd['sox'] = $bin_sox." ".$shellpath." -n trim 0 $(".$bin_exiftool." -s -s -s -duration# ".$shellpath." | awk '{print $1/10}') spectrogram -o - | ".$bin_convert." - -crop 800x515+58+30 -scale 515x515! +dither -colors 16 ".$tfile;
|
||||
$cmd['ffmpeg'] = $bin_ffmpeg." -ss $(( $(".$bin_mediainfo." --Inform='Video;%Duration%' ".$shellpath." | cut -d'.' -f1) / 10000 )) -i ".$shellpath." -vframes 1 -filter:v scale='400:-1' -q:v 3 ".$tfile;
|
||||
|
||||
$cmd['ql-thumbnail'] = $bin_qlthumb." ".$shellpath." ".$tfile." public.jpeg ".$p['thumb_size']." ".$p['thumb_size']." .8";
|
||||
$cmd['qlmanage'] = "qlmanage -t -s ".$p['thumb_size']." -o ".dirname($tpfile)." ".$shellpath."; sips -s format jpeg -s formatOptions 80 ".escapeshellarg($tpfile)." --out ".$tfile;
|
||||
|
||||
if (in_array($ext, $p['t_files']['sips'])) {
|
||||
$external_tool = "sips";
|
||||
} elseif (in_array($ext, $p['t_files']['ffmpeg'])) {
|
||||
$external_tool = "ffmpeg";
|
||||
} elseif (in_array($ext, $p['t_files']['sox'])) {
|
||||
$external_tool = "sox";
|
||||
} else {
|
||||
$external_tool = null;
|
||||
}
|
||||
switch ($p['thumb_priority']) {
|
||||
// external tool priority
|
||||
case 0: $priority = array($external_tool,"ql-thumbnail","qlmanage"); break;
|
||||
// ql-thumbnail priority
|
||||
case 1: $priority = array("ql-thumbnail","qlmanage",$external_tool); break;
|
||||
// qlmanage priority
|
||||
case 2: $priority = array("qlmanage","ql-thumbnail",$external_tool); break;
|
||||
}
|
||||
|
||||
$stmt->BindValue(":fid",$fid);
|
||||
$stmt->BindValue(":created",time());
|
||||
|
||||
$dfile = $bpath."/thumbs/".substr($fid, 0, 2)."/".$fid.".jpg";;
|
||||
if (!is_dir(dirname($dfile))) { @mkdir(dirname($dfile)); }
|
||||
|
||||
foreach ($priority as $tool) {
|
||||
|
||||
if (empty($cmd[$tool])) { continue; }
|
||||
|
||||
shell_exec($cmd[$tool]." 2>&1");
|
||||
echo " ->".$tool;
|
||||
|
||||
$checksize = @filesize($tfile);
|
||||
if ($checksize && !in_array($checksize,$discard)) {
|
||||
echo " ->use";
|
||||
$stmt->BindValue(":tool",$tool);
|
||||
$stmt->BindValue(":relative_path",substr($dfile, strlen($bpath)));
|
||||
list($width, $height) = getimagesize($tfile);
|
||||
$stmt->BindValue(":width",$width);
|
||||
$stmt->BindValue(":height",$height);
|
||||
rename($tfile,$dfile);
|
||||
break;
|
||||
} else {
|
||||
echo " ->discard";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
echo " ->db";
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user