From 6e6caa7ac093e32edaa9c43ff59209e8878f7187 Mon Sep 17 00:00:00 2001 From: profiteroles Date: Tue, 7 May 2019 01:55:42 -0700 Subject: [PATCH] 0.8.11 --- leaf.php | 87 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/leaf.php b/leaf.php index d3d7dae..b492e57 100644 --- a/leaf.php +++ b/leaf.php @@ -1,7 +1,10 @@ levels adjustment for resulting image (ex. \"0-253,0-2,0-255\") + -trim= pixels to trim from top, right, left, bottom build combine images into a pdf with img2pdf clean remove scratch files crop define EXIF crop values using template files @@ -340,13 +344,43 @@ echo Welcome("Crop using row/column brightness method"); if (args("levels")) { $adjust = args("levels"); } + +if (args("trim")) { + $parts = explode(",",args("trim")); + $top_trim = $parts[0]; + $right_trim = $parts[1]; + $left_trim = $parts[2]; + $bottom_trim = $parts[3]; + } -msg("Checking crops"); +echo "Building crop threads: "; $files = glob(args("dir")."*.*"); foreach ($files as $file) { + + if (isset($adjust)) { + $adjfile = "\( ".$file." -level ".$adjust." \)"; + } else { + $adjfile = $file; + } + + $cmd_a = "convert \( ".$adjfile." +repage -scale x1! -bordercolor black -border 1 -fuzz 30% -trim \) -format \"%w\n%O\" info: > scratch/".basename($file)."_autocropx.txt"; + $cmd_b = "convert \( ".$adjfile." +repage -scale 1x! -bordercolor black -border 1 -fuzz 60% -trim \) -format \"%h\n%O\" info: > scratch/".basename($file)."_autocropy.txt"; + $cmd_c = "exiftool -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom -ImageWidth -ImageHeight ".$file." > scratch/".basename($file)."_stats.txt"; - $tags = chop(shell_exec("exiftool -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom -ImageWidth -ImageHeight ".$file." 2>&1")); + $thread[] = array(".", $cmd_a); + $thread[] = array(".", $cmd_b); + $thread[] = array(".", $cmd_c); + + } + +multiexec($thread,$xt,false); + +echo "\n"; + +foreach ($files as $file) { + + $tags = file_get_contents("scratch/".basename($file)."_stats.txt"); foreach (explode("\n", trim($tags)) as $tag) { $parts = explode(":", $tag); $attr[trim($parts[0])] = trim($parts[1]); @@ -365,30 +399,24 @@ foreach ($files as $file) { echo "\nNo existing crop values for ".$file; } - if (isset($adjust)) { - $adjfile = "\( ".$file." -level ".$adjust." \)"; - } else { - $adjfile = $file; - } + $detectx = explode("\n",file_get_contents("scratch/".basename($file)."_autocropx.txt")); + $detecty = explode("\n",file_get_contents("scratch/".basename($file)."_autocropy.txt")); + $detectxparts = explode("+", chop($detectx[1])); + $detectyparts = explode("+", chop($detecty[1])); - $detectx = explode("\n",chop(@shell_exec("convert \( ".$adjfile." +repage -scale x1! -bordercolor black -border 1 -fuzz 30% -trim \) -format \"%w\n%O\" info: 2>&1"))); - $detecty = explode("\n",chop(@shell_exec("convert \( ".$adjfile." +repage -scale 1x! -bordercolor black -border 1 -fuzz 60% -trim \) -format \"%h\n%O\" info: 2>&1"))); - $detectxparts = explode("+", $detectx[1]); - $detectyparts = explode("+", $detecty[1]); - - if ($debug) { echo "\n".bashcolor("imgk values: cwidth: ".$detectx[0].", cheight: ".$detecty[0].", xoff: ".$detectxparts[1].", yoff: ".$detectxparts[2].", width: ".$width.", height: ".$height, "white","light purple"); } + if ($debug) { echo "\n".bashcolor("imgk values: cwidth: ".$detectx[0].", cheight: ".$detecty[0].", xoff: ".$detectxparts[1].", yoff: ".$detectxparts[2].", width: ".$width.", height: ".$height, "light purple"); } if (isset($detectx[0]) && $detectx[0] > 1) { $cwidth = $detectx[0]; } else { $cwidth = null; } if (isset($detecty[0]) && $detecty[0] > 1) { $cheight = $detecty[0]; } else { $cheight = null; } if (isset($detectxparts[1]) && $detectxparts[1] > 1) { $xoff = $detectxparts[1]; } else { $xoff = null; } - if (isset($detectxparts[2])) { $yoff = $detectxparts[2]; } else { $yoff = null; } + if (isset($detectyparts[2])) { $yoff = $detectyparts[2]; } else { $yoff = null; } if ($cwidth && $cheight && $xoff && $yoff) { list($ntop, $nright, $nleft, $nbottom) = crop_imgk_to_xmp($cwidth, $cheight, $xoff, $yoff, $width, $height); - + echo "\nNew crop values for ".$file.": "; - echo "\tTop: ".bashcolor($ntop, "blue"); + echo "\t\tTop: ".bashcolor($ntop, "blue"); echo "\tRight: ".bashcolor($nright, "green"); echo "\tLeft: ".bashcolor($nleft, "cyan"); echo "\tBottom: ".bashcolor($nbottom, "red"); @@ -403,14 +431,29 @@ foreach ($files as $file) { } - $thread[] = array($msg, $cmd); - - echo "\n".$msg; exec($cmd); + $threadx[] = array($msg, $cmd); } -//msg("Write crop values?",2); -//multiexec($thread,$xt); +echo "\n\n"; + +msg("Write crop values?",2); +multiexec($threadx,$xt); + +fin(); + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Note: Folders +////////////////////// +} elseif (args("app") == "folders") { +echo Welcome("Move digicam images into folders"); +///////////////////////////////////////////////////////////////////////// + +if (file_exists("tenrecjpg") || file_exists("tenrecdng")) { + msg("Folder already exists",1); + } + +exec("mkdir tenrecdng; mkdir tenrecjpg; mv *.JPG tenrecjpg/; mv *.DNG tenrecdng/"); fin();