From 1806fcf0dc6cbf3911cf2d46120f203b9f168e99 Mon Sep 17 00:00:00 2001 From: profiteroles Date: Tue, 7 May 2019 01:53:33 -0700 Subject: [PATCH] 0.7.0 --- leaf.php | 78 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/leaf.php b/leaf.php index 8df032b..60bb08f 100644 --- a/leaf.php +++ b/leaf.php @@ -2,14 +2,14 @@ /dev/null & ",$cmd)." & wait"; - echo $echo; - if (strlen($echo) > 1) { - echo "\n"; + if (strlen($msg[0]) > 1) { + $echo = implode("\n", $msg)."\n"; + } else { + $echo = implode("", $msg); } + if ($null) { + $exec = implode(" > /dev/null & ",$cmd)." & wait"; + } else { + $exec = implode(" & ",$cmd)." & wait"; + } + echo $echo; exec($exec); } } @@ -851,10 +856,10 @@ foreach ($files as $file) { echo "Processing ".$file.": "; $ext = pathinfo($file, PATHINFO_EXTENSION); if ($ext == "jpg" | $ext == "JPG" | $ext == "DNG") { - $parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom ".$file." 2>&1")); - if (strlen($parts) > 1) { list($top, $right, $left, $bottom) = explode("\n", $parts); } - if (isset($top) | isset($right) | isset($left) | isset($bottom)) { - shell_exec("exiftool -overwrite_original -XMP-crs:CropTop= -XMP-crs:CropRight= -XMP-crs:CropLeft= -XMP-crs:CropBottom= ".$file." 2>&1"); + $parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom -XMP-crs:CropAngle ".$file." 2>&1")); + if (strlen($parts) > 1) { @list($top, $right, $left, $bottom, $angle) = explode("\n", $parts); } + if (isset($top) | isset($right) | isset($left) | isset($bottom) | isset($angle)) { + shell_exec("exiftool -overwrite_original -XMP-crs:CropTop= -XMP-crs:CropRight= -XMP-crs:CropLeft= -XMP-crs:CropBottom= -XMP-crs:CropBottom= ".$file." 2>&1"); echo "removed"; } else { echo "no crop found"; @@ -882,7 +887,6 @@ if (args("max")) { if (null !== args("pad")) { $deskew_padding = args("pad"); - echo "pad = ".args("pad"); } else { $deskew_padding = 80; } @@ -899,8 +903,6 @@ if (args("size")) { $deskew_size = 2200; } -die; - $files = glob(args("dir")."*.{jpg,JPG,dng,DNG}", GLOB_BRACE); echo "Scanning for crop values: "; @@ -974,29 +976,59 @@ if (!args("nomap")) { $thread = null; echo "\n"; -msg("Detecting skew..."); +echo "Deskewing with ".$xt." threads: "; foreach ($files as $file) { - + + $ext = pathinfo($file,PATHINFO_EXTENSION); + if (args("nomap")) { $dmfile = $file; } else { - $ext = pathinfo($file,PATHINFO_EXTENSION); $dmfile = "scratch/".basename($file, ".".$ext)."_dmap.jpg"; } + + $txtfile = "scratch/".basename($file, ".".$ext)."_angle.txt"; + + if (file_exists($txtfile)) { - $result = shell_exec("deskew -o /tmp/null -l 99 \"".$dmfile."\" 2>&1"); - $arr = explode("Skew angle found: ", $result); - $angle = substr($arr[1], 0, 4); - $msg = $file.": ".$angle; + $msg = "o"; + $cmd = "true"; + + } else { + + $msg = "."; + $cmd = "deskew -o /tmp/null -l 99 ".$dmfile." | grep 'Skew angle found:' | cut -f2- -d: | tr -d ' \n' > ".$txtfile; + + } + + $thread[] = array($msg, $cmd); + + } + +multiexec($thread,$xt,false); + +echo "\n\n"; + +foreach ($files as $file) { + + $txtfile = "scratch/".basename($file, ".".$ext)."_angle.txt"; + $angle = file_get_contents($txtfile); + + $msg = $file." = ".$angle; + if ($angle > $deskew_max_angle | $angle < ($deskew_max_angle*-1)) { $msg .= " (too big)"; } else { $angles[$file] = $angle; } + msg($msg); + } +$thread = null; + echo "\n\n"; echo "Checking for existing rotation: "; @@ -1030,7 +1062,9 @@ foreach ($files as $file) { } -echo "\n\n"; +echo "\n"; + +msg("Write to EXIF?",2); if (is_array($thread)) {