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

View File

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