setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbp->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); echo "\nBatch (".$mode."): ".basename($pathname); switch ($mode) { // Icons ////////////////////////////////////////// case "icons": if ($p['icon_tool'] == 0) { $tool = "qltool"; } elseif ($p['icon_tool'] == 1) { $tool = "qlmanage"; } if (in_array($ext, $p['i_skip'])) { // file extension is in the skip list echo " ->i_skip"; break; } $tfile = "/tmp/Yuba/".$mytime."/".substr($fid,0,3)."/".$file.".png"; if (!is_dir(dirname($tfile))) { @mkdir(dirname($tfile)); } // workaround for qlmanage naming convention $rowid = @$dbp->query("SELECT rowid FROM icons WHERE fid='".$fid."'")->fetch()['rowid']; // check for existing icon generation attempt if (!$rowid) { // no prior attempt $stmt = $dbp->prepare("INSERT INTO icons VALUES (:fid, :hash, :created, :relative_path, :tool)"); echo " ->generate"; } elseif ($rowid && $p['icons'] == 2) { // prior attempt but rebuild mode $stmt = $dbp->prepare("UPDATE icons SET fid = :fid, hash = :hash, created = :created, relative_path = :relative_path, tool = :tool WHERE rowid = ".$rowid); echo " ->rebuild"; } else { // prior attempt echo " ->skip"; break; } $stmt->BindValue(":fid",$fid); if ($tool == "qltool") { $cmd = $bin_qltool." di ".$shellpath." ".$p['icon_size']." ".$p['icon_size']." | base64 --decode > ".escapeshellarg($tfile); } elseif ($tool == "qlmanage") { // > code for custom qlgenerator bindings goes here < $cmd = "qlmanage -ti -f ".floor($p['icon_size']/128)." -o ".basename($tfile)." ".$shellpath; } shell_exec($cmd); if (@filesize($tfile)) { $hash = md5_file($tfile); $stmt->BindValue(":hash",$hash); if ($row = @$dbp->query("SELECT * FROM icons WHERE hash='".$hash."'")->fetchAll()[0]) { // check for another icon with the same hash $stmt->BindValue(":created",$row['created']); $stmt->BindValue(":relative_path",$row['relative_path']); $stmt->BindValue(":tool",$row['tool']); echo " ->recycle"; } else { $dfile = $bpath."/icons/".substr($hash, 0, 2)."/".$hash.".png"; if (!is_dir(dirname($dfile))) { @mkdir(dirname($dfile)); } 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 { shell_exec($bin_convert." ".escapeshellarg($tfile)." -strip -define png:compression-level=9 ".$dfile); } $stmt->BindValue(":created",time()); $stmt->BindValue(":relative_path",substr($dfile,strlen($bpath))); $stmt->BindValue(":tool",$tool); } } else { echo " ->discard"; } $stmt->execute(); break; case "thumbs": // Thumbs ////////////////////////////////////////// // "bad" filesizes $discard = array( 3953, 4977, 5019, 6059, 6616, 17393 ); break; } echo "\n"; ?>