From 42606ddcf6f65c9e5ebd83299942fce6e63aa28b Mon Sep 17 00:00:00 2001 From: profiteroles Date: Thu, 7 Nov 2019 07:52:32 -0800 Subject: [PATCH] 0.9.0.2 --- CHANGELOG.md | 5 ++++ current_version.txt | 2 +- leaf.php | 61 +++++++++++++++++++++++++++++++-------------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c944164..3ea1317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +[0.9.0.2] + +- Option to mix levels adjustment with original +- Removed "a" flag from trash command + [0.9.0.1] - Better tmp dir diff --git a/current_version.txt b/current_version.txt index e608a6e..ddbecfe 100644 --- a/current_version.txt +++ b/current_version.txt @@ -1 +1 @@ -0.9.0.1 \ No newline at end of file +0.9.0.2 \ No newline at end of file diff --git a/leaf.php b/leaf.php index cbeacfa..d3613d4 100644 --- a/leaf.php +++ b/leaf.php @@ -3,7 +3,7 @@ // Leaf - Tools for Book Scans // No license, do not distribute -$version = "0.9.0.1"; +$version = "0.9.0.2"; $time_start = microtime(true); date_default_timezone_set("America/Los_Angeles"); $tmpdir = "/tmp/leaf/".time()."/"; @@ -307,7 +307,9 @@ generate create final jpg images for pdf creation -pixels= scale to x pixels on longest side -inches= set dpi to x inches on longest side -q=<0-100> (90) jpeg quality - -levels= photoshop levels adjustment (ex. \"0-253,0-2,0-255\") + -levels= photoshop levels adjustment (ex. \"10,.9,235\") + -olevels= output levels adjustment (ex. \"0,250\") + -mix= percentage to mix with original (0-100, 90=mostly original) -px= png size multiplier -plevels= png levels adjustment (otherwise calculated from adjust) -pt=<0-255> use threshold method with photoshop level value @@ -539,7 +541,7 @@ if (!args("mpush")) { if (count(glob($dest."/*.*"))) { msg("Files already exist in ".$dest.". Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); mkdir($dest); } elseif (!is_dir($dest)) { mkdir($dest); @@ -592,7 +594,7 @@ $dest = rtrim(args("dir"), '/')."_despined"; if (count(glob($dest."/*.*"))) { msg("Files already exist in ".$dest.". Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); mkdir($dest); } elseif (!is_dir($dest)) { mkdir($dest); @@ -722,7 +724,7 @@ $dest = rtrim(args("dir"), '/')."_generated"; if (count(glob($dest."/*.*"))) { msg("Files already exist in ".$dest.". Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); mkdir($dest); } elseif (!is_dir($dest)) { mkdir($dest); @@ -847,6 +849,7 @@ foreach ($jpg as $parts) { $file = $parts[0]; $output = $dest."/".basename($file); + $iscolor = false; if (isset($parts[3]) && $parts[3] == 1) { @@ -866,24 +869,36 @@ foreach ($jpg as $parts) { if (args("skipc")) { continue; } + $iscolor = true; + $msg = "Processing color page ".$file." @ ".$dims."!"; $cmd = "convert -resize ".$dims."\! "; - if (args("modulate")) { - $msg .= " (".args("modulate").")"; - $cmd .= "-modulate ".args("modulate")." "; - } - } + $levelcmd = ""; + if (args("levels")) { $msg .= " (".args("levels").")"; - $cmd .= "-level ".args("levels")." "; + $levelcmd .= "-level ".args("levels")." "; } if (args("olevels")) { $msg .= " (".args("olevels").")"; - $cmd .= "+level ".args("olevels")." "; + $levelcmd .= "+level ".args("olevels")." "; + } + + if ($iscolor && args("modulate")) { + $msg .= " (".args("modulate").")"; + $levelcmd .= "-modulate ".args("modulate")." "; + } + + if (args("mix") && $levelcmd) { + // if this is a mix, we reset the $cmd so we can nest the levels command and mix with og + $msg .= " "; + $cmd = "convert \( ".$file." -resize ".$dims."\! ".$levelcmd."\) \( ".$file." -resize ".$dims."\! \) -define compose:args=".args("mix")." -compose blend -composite "; + } else { + $cmd .= $levelcmd; } if (args("unsharp")) { @@ -892,7 +907,15 @@ foreach ($jpg as $parts) { } $msg .= " [Q=".$quality."]"; - $cmd .= "-quality ".$quality." ".$file." ".$output; + $cmd .= "-quality ".$quality." "; + + if (args("mix") && $levelcmd) { + $cmd .= $output; + } else { + $cmd .= $file." ".$output; + } + + //echo $cmd."\n"; $thread_a[] = array($msg, $cmd); $thread_b[] = array(".","exiftool -overwrite_original -Xresolution=".$dpi." -Yresolution=".$dpi." -jfif:Xresolution=".$dpi." -jfif:Yresolution=".$dpi." ".$output); @@ -1020,7 +1043,7 @@ msg("Remove scratch files?",2); if (!is_dir("scratch")) { msg("Problem with scratch dir",2); } else { - exec("/opt/local/bin/trash -a scratch/"); + exec("/opt/local/bin/trash scratch/"); } fin(); @@ -1035,7 +1058,7 @@ echo Welcome("Edge detection"); $dest = rtrim(args("dir"), '/')."_edges"; if (count(glob($dest."/*.*"))) { msg("Files already exist in ".$dest.". Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); mkdir($dest); } elseif (!is_dir($dest)) { mkdir($dest); @@ -1085,7 +1108,7 @@ if (args("x")) { $dest = rtrim(args("dir"), '/')."_rotated"; if (count(glob($dest."/*.*"))) { msg("Files already exist in ".$dest.". Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); mkdir($dest); } elseif (!is_dir($dest)) { mkdir($dest); @@ -1597,7 +1620,7 @@ $input = args("dir")."*.*"; $dest = basename(getcwd()).".pdf"; if (file_exists($dest)) { msg("Files ".$dest." already exists. Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); } echo "Creating pdf...\n\n"; exec("img2pdf --verbose --viewer-page-layout twocolumnright --author 'Leaf ".$version."' --output ".$dest." ".$input); @@ -1649,7 +1672,7 @@ exec("pdftk ".$file." cat ".$items."output ".$output); echo "\n"; msg("Remove original file?",2); -exec("/opt/local/bin/trash -a ".$file."; mv ".$output." ".$file); +exec("/opt/local/bin/trash ".$file."; mv ".$output." ".$file); fin(); @@ -1704,7 +1727,7 @@ $dest = rtrim(args("dir"), '/')."_divided"; if (count(glob($dest."/*.*"))) { msg("Files already exist in ".$dest.". Move to trash?",2); - exec("/opt/local/bin/trash -a ".$dest); + exec("/opt/local/bin/trash ".$dest); mkdir($dest); } elseif (!is_dir($dest)) { mkdir($dest);