0.8.10
This commit is contained in:
84
leaf.php
84
leaf.php
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
// Leaf - Tools for Book Scans
|
||||
$version = "0.8.8";
|
||||
$version = "0.8.10";
|
||||
$time_start = microtime(true);
|
||||
date_default_timezone_set("America/Los_Angeles");
|
||||
|
||||
@@ -17,12 +17,12 @@ if (in_array($cores,$reasonable_cores)) {
|
||||
|
||||
// Functions
|
||||
|
||||
function crop_imgk_to_xmp($width, $height, $xoff, $yoff) {
|
||||
function crop_imgk_to_xmp($cwidth, $cheight, $xoff, $yoff, $width, $height) {
|
||||
|
||||
$top = $yoff/$height;
|
||||
$right = (($width-$xoff)/$width);
|
||||
$right = (($xoff+$cwidth)/$width);
|
||||
$left = $xoff/$width;
|
||||
$bottom = (($height-$yoff)/$height);
|
||||
$bottom = (($yoff+$cheight)/$height);
|
||||
|
||||
return array(number_format($top,6), number_format($right,6), number_format($left,6), number_format($bottom,6));
|
||||
|
||||
@@ -245,6 +245,7 @@ USAGE: leaf [mode] [-options] directory
|
||||
|
||||
Modes:
|
||||
autocrop crop using row/column brightness method
|
||||
-levels=<params> levels adjustment for resulting image (ex. \"0-253,0-2,0-255\")
|
||||
build combine images into a pdf with img2pdf
|
||||
clean remove scratch files
|
||||
crop define EXIF crop values using template files
|
||||
@@ -336,34 +337,71 @@ foreach ($picks as $file) {
|
||||
echo Welcome("Crop using row/column brightness method");
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (args("levels")) {
|
||||
$adjust = args("levels");
|
||||
}
|
||||
|
||||
msg("Checking crops");
|
||||
|
||||
$files = glob(args("dir")."*.*");
|
||||
foreach ($files as $file) {
|
||||
|
||||
$parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom ".$file." 2>&1"));
|
||||
@list($top, $right, $left, $bottom) = explode("\n", $parts);
|
||||
echo "\nExisting crop values for ".$file.": ";
|
||||
echo "\tTop: ".bashcolor($top, "light blue");
|
||||
echo "\tRight: ".bashcolor($right, "light green");
|
||||
echo "\tLeft: ".bashcolor($left, "light cyan");
|
||||
echo "\tBottom: ".bashcolor($bottom, "light red");
|
||||
$tags = chop(shell_exec("exiftool -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom -ImageWidth -ImageHeight ".$file." 2>&1"));
|
||||
foreach (explode("\n", trim($tags)) as $tag) {
|
||||
$parts = explode(":", $tag);
|
||||
$attr[trim($parts[0])] = trim($parts[1]);
|
||||
}
|
||||
|
||||
$detectx = explode("\n",chop(shell_exec("convert \( $file +repage -scale x1! -bordercolor black -border 1 -fuzz 30% -trim \) -format \"%w\n%O\" info:")));
|
||||
$detecty = explode("\n",chop(shell_exec("convert \( $file +repage -scale 1x! -bordercolor black -border 1 -fuzz 60% -trim \) -format \"%h\n%O\" info:")));
|
||||
$width = $attr['Image Width'];
|
||||
$height = $attr['Image Height'];
|
||||
|
||||
if (isset($attr['Crop Top']) && isset($attr['Crop Right']) && isset($attr['Crop Left']) && isset($attr['Crop Bottom'])) {
|
||||
echo "\nExisting crop values for ".$file.": ";
|
||||
echo "\tTop: ".bashcolor($attr['Crop Top'], "light blue");
|
||||
echo "\tRight: ".bashcolor($attr['Crop Right'], "light green");
|
||||
echo "\tLeft: ".bashcolor($attr['Crop Left'], "light cyan");
|
||||
echo "\tBottom: ".bashcolor($attr['Crop Bottom'], "light red");
|
||||
} else {
|
||||
echo "\nNo existing crop values for ".$file;
|
||||
}
|
||||
|
||||
if (isset($adjust)) {
|
||||
$adjfile = "\( ".$file." -level ".$adjust." \)";
|
||||
} else {
|
||||
$adjfile = $file;
|
||||
}
|
||||
|
||||
$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]);
|
||||
|
||||
list($ntop, $nright, $nleft, $nbottom) = crop_imgk_to_xmp($detectx[0], $detecty[0], $detectxparts[1], $detectxparts[2]);
|
||||
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"); }
|
||||
|
||||
echo "\nNew crop values for ".$file.": ";
|
||||
echo "\tTop: ".bashcolor($ntop, "blue");
|
||||
echo "\tRight: ".bashcolor($nright, "green");
|
||||
echo "\tLeft: ".bashcolor($nleft, "cyan");
|
||||
echo "\tBottom: ".bashcolor($nbottom, "red");
|
||||
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; }
|
||||
|
||||
$msg = "Setting crop values for ".$file;
|
||||
$cmd = "exiftool -overwrite_original -XMP-crs:HasCrop=1 -XMP-crs:AlreadyApplied=0 -XMP-crs:CropTop=".$ntop." -XMP-crs:CropRight=".$nright." -XMP-crs:CropLeft=".$nleft." -XMP-crs:CropBottom=".$nbottom." ".$file;
|
||||
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 "\tRight: ".bashcolor($nright, "green");
|
||||
echo "\tLeft: ".bashcolor($nleft, "cyan");
|
||||
echo "\tBottom: ".bashcolor($nbottom, "red");
|
||||
|
||||
$msg = "Setting crop values for ".$file;
|
||||
$cmd = "exiftool -overwrite_original -XMP-crs:HasCrop=1 -XMP-crs:AlreadyApplied=0 -XMP-crs:CropTop=".$ntop." -XMP-crs:CropRight=".$nright." -XMP-crs:CropLeft=".$nleft." -XMP-crs:CropBottom=".$nbottom." ".$file;
|
||||
|
||||
} else {
|
||||
|
||||
$msg = "Incomplete crop values for ".$file.", skipping...";
|
||||
$cmd = "true";
|
||||
|
||||
}
|
||||
|
||||
$thread[] = array($msg, $cmd);
|
||||
|
||||
@@ -1343,7 +1381,7 @@ fin();
|
||||
echo Welcome("Insert image into numbered sequence");
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$files = glob(args("dir")."[0-9][0-9][0-9]-*.jpg");
|
||||
$files = glob(args("dir")."[0-9][0-9][0-9]-*.*");
|
||||
$count = count($files);
|
||||
|
||||
if (!$count) {
|
||||
@@ -1387,7 +1425,7 @@ foreach ($ops as $parts) {
|
||||
rename($parts[0], $parts[1]);
|
||||
}
|
||||
|
||||
fin("Starting file count: ".$count."; Ending file count: ".count(glob(args("dir")."[0-9][0-9][0-9]-*.jpg")));
|
||||
fin("Starting file count: ".$count."; Ending file count: ".count(glob(args("dir")."[0-9][0-9][0-9]-*.*")));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Note: Review
|
||||
|
||||
Reference in New Issue
Block a user