This commit is contained in:
2019-05-07 01:53:47 -07:00
parent 1806fcf0dc
commit b0861846be

View File

@@ -2,7 +2,7 @@
<?php
// Leaf - Tools for Book Scans
$version = "0.7.0";
$version = "0.7.1";
$time_start = microtime(true);
date_default_timezone_set("America/Los_Angeles");
$xt = 3; // threads
@@ -57,7 +57,7 @@ function fin($print = null) {
if (isset($print)) {
echo "\n".$print;
}
echo "\nFinished in ".floor($time = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"])." seconds\n";
echo "\nFinished in ".floor($time = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"])." seconds\n\n";
die;
}
@@ -159,10 +159,12 @@ deskew detect rotation angles
-pad=<num> pixels to pad around crop area, default 80
-contrast=<num> contrast boost, default 20
-size=<num> size in pixels of dmap, default 2200
-nomap don't use dmaps
divide wrapper for imagemagick Divide_Src
-map=<file> specify brightness file
-adjust=<params> levels adjustment (ex. \"0%,98%,.9\")
-q=<quality> quality out of 100
-pages map file is for LR rotated pages
dupes Find duplicate images using computed PHASH on thumbnails
-threshold=<num> match threshold
-walk=<num> comparison scope (compare n image to n, n+1, n+2, etc)
@@ -187,6 +189,49 @@ strip strip exif crop values from images with exiftool
echo $help;
fin();
////////////////////////////////////////////////////////////////////////////////////////////////
// Note: Generate
//////////////////////
} elseif (args("app") == "generate") {
echo Welcome("Generate final jpg images");
/////////////////////////////////////////////////////////////////////////
$files = glob(args("dir")."*.{jpg,JPG}", GLOB_BRACE);
echo "Checking EXIF values: ";
foreach ($files as $file) {
echo ".";
$lines = shell_exec("exiftool -s -s -s -f -Label -ConvertToGrayscale ".$file);
$parts = explode("\n", $lines);
if ($parts[0] == "bitmap") {
$bitmap[] = $file;
} elseif ($parts[1] == "True") {
$grey[] = $file;
} else {
$color[] = $file;
}
}
echo "\n\n";
echo "Bitmap files: ";
if (is_array($bitmap)) { echo count($bitmap); } else { echo "None"; }
echo "\n\n";
echo "Greyscale files: ";
if (is_array($grey)) { echo count($grey); } else { echo "None"; }
echo "\n\n";
echo "Color files: ";
if (is_array($color)) { echo count($color); } else { echo "None"; }
echo "\n\n";
fin();
////////////////////////////////////////////////////////////////////////////////////////////////
// Note: Clean
//////////////////////
@@ -748,6 +793,12 @@ echo Welcome("Composite image from brightness map");
$files = glob(args("dir")."*.{jpg,JPG,tif}", GLOB_BRACE);
if (args("pages")) {
$pages = true;
} else {
$pages = false;
}
if (!args("map")) {
msg("No brightness map specified",1);
} elseif (!file_exists(args("map"))) {
@@ -777,6 +828,8 @@ if (args("q")) {
$quality = 95;
}
echo "Building threads: ";
$thread = array();
foreach ($files as $file) {
$msg = "Dividing ".$file." with ".$map.", Q=".$quality;
@@ -794,8 +847,24 @@ foreach ($files as $file) {
} else {
$cmd = "convert ".$file." ".$tmap." -compose Divide_Src -composite -quality ".$quality." ".$dest."/".basename($file);
}
if ($pages) {
$label = trim(shell_exec("exiftool -s -s -s -Label ".$file));
if ($label == "non-page") {
$msg .= "<Skipping non-page>";
$cmd = "true";
echo "o";
} else {
echo ".";
}
} else {
echo ".";
}
$cmd = "true";
$thread[] = array($msg, $cmd);
}
echo "\n\n";
msg("Beginning multithreaded convert with ".$xt." threads");
multiexec($thread,$xt);
@@ -1029,7 +1098,7 @@ foreach ($files as $file) {
$thread = null;
echo "\n\n";
echo "\n";
echo "Checking for existing rotation: ";
@@ -1062,17 +1131,19 @@ foreach ($files as $file) {
}
echo "\n";
echo "\n\n";
msg("Write to EXIF?",2);
if (is_array($thread)) {
msg("Writing EXIF tags with ".$xt." threads");
//multiexec($thread,$xt);
multiexec($thread,$xt);
}
fin();
////////////////////////////////////////////////////////////////////////////////////////////////
// Elif
//////////////////////