This commit is contained in:
2019-05-07 01:55:03 -07:00
parent 1744484ff4
commit 158a35ee7b

View File

@@ -1,8 +1,7 @@
<?php
// Leaf - Tools for Book Scans
$version = "0.8.6";
$debug = 1;
$version = "0.8.7";
$time_start = microtime(true);
date_default_timezone_set("America/Los_Angeles");
@@ -15,7 +14,7 @@ if (in_array($cores,$reasonable_cores)) {
} else {
$xt = 2;
}
// Functions
function levels_ps_to_imgk($string) {
@@ -24,8 +23,8 @@ function levels_ps_to_imgk($string) {
msg("Invalid levels string",1);
} else {
$black = (number_format(($parts[0]/253),5)*100)."%";
$white = (number_format(($parts[1]/255),5)*100)."%";
$gamma = $parts[2];
$white = (number_format(($parts[2]/255),5)*100)."%";
$gamma = $parts[1];
return $black.",".$white.",".$gamma;
}
}
@@ -65,7 +64,7 @@ function multiexec($thread, $x, $null = true) {
$exec = implode($pipe." & ",$cmd).$pipe." & wait";
echo $echo;
if ($debug) {
echo "\n".str_replace($pipe." & ", "\n\n", $exec)."\n";
echo "\n".str_replace($pipe." & ", "\n\n", $exec)."\n\n";
}
@exec($exec);
}
@@ -144,8 +143,13 @@ function args($query) {
function Welcome($msg) {
global $version;
$out = "\033[1;1H\033[2J"; // clear screen
$out .= bashcolor("Leaf Version: ".$version, "white", "magenta")." ".shell_exec("date");
global $debug;
if ($debug) {
$out .= bashcolor("Leaf Version: ".$version." debug", "white", "red")." ".shell_exec("date");
} else {
$out = "\033[1;1H\033[2J"; // clear screen
$out .= bashcolor("Leaf Version: ".$version, "white", "magenta")." ".shell_exec("date");
}
$out .= $msg."\n\n";
return $out;
}
@@ -183,6 +187,12 @@ if (args("dir") && !is_dir(args("dir"))) {
if (!is_dir("scratch")) {
mkdir("scratch");
}
if (args("debug")) {
$debug = 1;
} else {
$debug = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Note: Help
@@ -207,18 +217,18 @@ deskew detect rotation angles
-nomap don't use dmaps
depaper divide page with itself using mask (better despine)
-mask=<file> mask file for spine-left image
-mpush=<levels> levels for divide map (ex. \"0-253,0-255,0-2\")
-mpush=<levels> levels for divide map (ex. \"0-253,0-2,0-255\")
-mix=<0-100> (null) percentage mix with original (90% = mostly og)
-skip=<label> (null) skip files with this label
despine remove shadow from spine
-levels=<params> levels for overlay (ex. \"0-253,0-255,0-2\")
-levels=<params> levels for overlay (ex. \"0-253,0-2,0-255\")
-width=<pixels> (300) spine width in pixels
-q=<0-100> (auto) jpeg quality, default read from source or 95
divide wrapper for imagemagick Divide_Src
-map=<file> specify brightness file
-mpush=<levels> levels for map (ex. \"0-253,0-255,0-2\") or \"auto\"
-mpush=<levels> levels for map (ex. \"0-253,0-2,0-255\") or \"auto\"
-blur=<pixels> apply in-place blur to map (slow/dumb)
-levels=<params> levels adjustment for resulting image (ex. \"0-253,0-255,0-2\")
-levels=<params> levels adjustment for resulting image (ex. \"0-253,0-2,0-255\")
-q=<quality> (95) quality out of 100
-pages map file is for LR rotated pages
-mix=<0-100> percentage mix with original (90% = mostly og)
@@ -231,7 +241,7 @@ generate create final jpg images for pdf creation
-pixels=<num> scale to x pixels on longest side
-inches=<num> set dpi to x inches on longest side
-q=<0-100> (90) jpeg quality
-levels=<params> photoshop levels adjustment (ex. \"0-253,0-255,0-2\")
-levels=<params> photoshop levels adjustment (ex. \"0-253,0-2,0-255\")
-px=<num> png size multiplier
-plevels=<params> png levels adjustment (otherwise calculated from adjust)
-pt=<0-255> use threshold method with photoshop level value
@@ -630,13 +640,13 @@ if (isset($spine)) {
foreach ($jpg as $parts) {
continue;
$file = $parts[0];
$output = $dest."/".basename($file);
if (isset($parts[3]) && $parts[3] == 1) {
if (args("skipg")) { continue; }
$msg = "Processing greyscale page ".$file." @ ".$dims."!";
$cmd = "convert -resize ".$dims."\! -colorspace gray -type TrueColor ";
@@ -648,6 +658,8 @@ foreach ($jpg as $parts) {
} else {
if (args("skipc")) { continue; }
$msg = "Processing color page ".$file." @ ".$dims."!";
$cmd = "convert -resize ".$dims."\! ";
@@ -683,8 +695,8 @@ echo "\n";
msg("Setting DPI: ");
multiexec($thread_b,$xt);
if (isset($bitmap)) {
if (isset($bitmap) && !args("skipb")) {
if (!args("pt")) {
if (args("levels")) {
@@ -734,12 +746,12 @@ if (isset($bitmap)) {
if (args("pc") == "2!") { // a b&w bitmap image with an intermediary antialiased step (darker text)
$msg .= " (".$threshold.", ".$pl.")";
$msg .= " (".$threshold.", ".args("pc").")";
$cmd = "convert \( \( \( ".$file." -threshold ".$threshold." \) -set colorspace sRGB -type truecolor \) -resize ".$pngdims."\! \) -threshold 95% ".$output;
} elseif (args("pc") == "3") { // a b&w bitmap image with an additional color for antialiasing
$msg .= " (".$threshold.", ".$pl.")";
$msg .= " (".$threshold.", ".args("pc").")";
$cmd = "convert \( \( \( ".$file." -threshold ".$threshold." \) -set colorspace sRGB -type truecolor \) -resize ".$pngdims."\! \) -set colorspace Grayscale -colors 4 -depth 2 ".$output;
} else { // a b&w bitmap image
@@ -753,12 +765,12 @@ if (isset($bitmap)) {
if (args("pc") == "2!") { // a b&w bitmap image with an intermediary antialiased step (darker text)
$msg .= " (".$radjust.", ".$pl.")";
$msg .= " (".$radjust.", ".args("pc").")";
$cmd = "convert \( \( \( ".$file." -level ".$radjust." -monochrome -colors 2 -depth 1 ".$negate."\) -set colorspace sRGB -type truecolor \) -resize ".$pngdims."\! \) -threshold 95% ".$output;
} elseif (args("pc") == "3") { // a b&w bitmap image with an additional color for antialiasing
$msg .= " (".$radjust.", ".$pl.")";
$msg .= " (".$radjust.", ".args("pc").")";
$cmd = "convert \( ".$file." -level ".$radjust." -resize ".$pngdims."\! \) -set colorspace Grayscale -colors 4 -depth 2 ".$output;
} else { // a b&w bitmap image