0.7.0
This commit is contained in:
78
leaf.php
78
leaf.php
@@ -2,14 +2,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Leaf - Tools for Book Scans
|
// Leaf - Tools for Book Scans
|
||||||
$version = "0.6.9";
|
$version = "0.7.0";
|
||||||
$time_start = microtime(true);
|
$time_start = microtime(true);
|
||||||
date_default_timezone_set("America/Los_Angeles");
|
date_default_timezone_set("America/Los_Angeles");
|
||||||
$xt = 3; // threads
|
$xt = 3; // threads
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
|
|
||||||
function multiexec($thread, $x) {
|
function multiexec($thread, $x, $null = true) {
|
||||||
$batch = array_chunk($thread,$x);
|
$batch = array_chunk($thread,$x);
|
||||||
foreach ($batch as $group) {
|
foreach ($batch as $group) {
|
||||||
$msg = array();
|
$msg = array();
|
||||||
@@ -18,12 +18,17 @@ function multiexec($thread, $x) {
|
|||||||
$msg[] = $parts[0];
|
$msg[] = $parts[0];
|
||||||
$cmd[] = $parts[1];
|
$cmd[] = $parts[1];
|
||||||
}
|
}
|
||||||
$echo = implode("\n", $msg);
|
if (strlen($msg[0]) > 1) {
|
||||||
$exec = implode(" > /dev/null & ",$cmd)." & wait";
|
$echo = implode("\n", $msg)."\n";
|
||||||
echo $echo;
|
} else {
|
||||||
if (strlen($echo) > 1) {
|
$echo = implode("", $msg);
|
||||||
echo "\n";
|
|
||||||
}
|
}
|
||||||
|
if ($null) {
|
||||||
|
$exec = implode(" > /dev/null & ",$cmd)." & wait";
|
||||||
|
} else {
|
||||||
|
$exec = implode(" & ",$cmd)." & wait";
|
||||||
|
}
|
||||||
|
echo $echo;
|
||||||
exec($exec);
|
exec($exec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -851,10 +856,10 @@ foreach ($files as $file) {
|
|||||||
echo "Processing ".$file.": ";
|
echo "Processing ".$file.": ";
|
||||||
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
||||||
if ($ext == "jpg" | $ext == "JPG" | $ext == "DNG") {
|
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"));
|
$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) = explode("\n", $parts); }
|
if (strlen($parts) > 1) { @list($top, $right, $left, $bottom, $angle) = explode("\n", $parts); }
|
||||||
if (isset($top) | isset($right) | isset($left) | isset($bottom)) {
|
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= ".$file." 2>&1");
|
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";
|
echo "removed";
|
||||||
} else {
|
} else {
|
||||||
echo "no crop found";
|
echo "no crop found";
|
||||||
@@ -882,7 +887,6 @@ if (args("max")) {
|
|||||||
|
|
||||||
if (null !== args("pad")) {
|
if (null !== args("pad")) {
|
||||||
$deskew_padding = args("pad");
|
$deskew_padding = args("pad");
|
||||||
echo "pad = ".args("pad");
|
|
||||||
} else {
|
} else {
|
||||||
$deskew_padding = 80;
|
$deskew_padding = 80;
|
||||||
}
|
}
|
||||||
@@ -899,8 +903,6 @@ if (args("size")) {
|
|||||||
$deskew_size = 2200;
|
$deskew_size = 2200;
|
||||||
}
|
}
|
||||||
|
|
||||||
die;
|
|
||||||
|
|
||||||
$files = glob(args("dir")."*.{jpg,JPG,dng,DNG}", GLOB_BRACE);
|
$files = glob(args("dir")."*.{jpg,JPG,dng,DNG}", GLOB_BRACE);
|
||||||
|
|
||||||
echo "Scanning for crop values: ";
|
echo "Scanning for crop values: ";
|
||||||
@@ -974,29 +976,59 @@ if (!args("nomap")) {
|
|||||||
$thread = null;
|
$thread = null;
|
||||||
|
|
||||||
echo "\n";
|
echo "\n";
|
||||||
msg("Detecting skew...");
|
echo "Deskewing with ".$xt." threads: ";
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
||||||
|
$ext = pathinfo($file,PATHINFO_EXTENSION);
|
||||||
|
|
||||||
if (args("nomap")) {
|
if (args("nomap")) {
|
||||||
$dmfile = $file;
|
$dmfile = $file;
|
||||||
} else {
|
} else {
|
||||||
$ext = pathinfo($file,PATHINFO_EXTENSION);
|
|
||||||
$dmfile = "scratch/".basename($file, ".".$ext)."_dmap.jpg";
|
$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");
|
$msg = "o";
|
||||||
$arr = explode("Skew angle found: ", $result);
|
$cmd = "true";
|
||||||
$angle = substr($arr[1], 0, 4);
|
|
||||||
$msg = $file.": ".$angle;
|
} 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)) {
|
if ($angle > $deskew_max_angle | $angle < ($deskew_max_angle*-1)) {
|
||||||
$msg .= " (too big)";
|
$msg .= " (too big)";
|
||||||
} else {
|
} else {
|
||||||
$angles[$file] = $angle;
|
$angles[$file] = $angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg($msg);
|
msg($msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$thread = null;
|
||||||
|
|
||||||
echo "\n\n";
|
echo "\n\n";
|
||||||
|
|
||||||
echo "Checking for existing rotation: ";
|
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)) {
|
if (is_array($thread)) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user