From bf12ac723734e7ea88bd2f8e0fe47883bbf940f8 Mon Sep 17 00:00:00 2001 From: profiteroles Date: Tue, 7 May 2019 01:54:38 -0700 Subject: [PATCH] 0.8.4 --- leaf.php | 176 +++++++++++++++++++++++++++---------------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/leaf.php b/leaf.php index 2ca6f56..d8c0ad8 100644 --- a/leaf.php +++ b/leaf.php @@ -1,8 +1,8 @@ (20) levels attenuation -size= (2200) dmap size in pixels -nomap don't use dmaps +depaper divide page with itself using mask (better despine) + -mask= mask file for spine-left image + -mpush= levels for divide map (ex. \"0-253,0-255,0-2\") + -mix=<0-100> percentage mix with original (90% = mostly og) despine remove shadow from spine - -target= only process pages with spine similar to the spine of this target file -levels= levels for overlay (ex. \"0-253,0-255,0-2\") -width= (300) spine width in pixels -q=<0-100> (auto) jpeg quality, default read from source or 95 divide wrapper for imagemagick Divide_Src -map= specify brightness file - -levels= photoshop levels adjustment (ex. \"0-253,0-255,0-2\") + -mpush= levels for map (ex. \"0-253,0-255,0-2\") or \"auto\" + -blur= apply in-place blur to map (slow/dumb) + -levels= levels adjustment for resulting image (ex. \"0-253,0-255,0-2\") -q= (95) quality out of 100 -pages map file is for LR rotated pages -mix=<0-100> percentage mix with original (90% = mostly og) @@ -247,6 +252,46 @@ foreach ($files as $file) { fin(); +//////////////////////////////////////////////////////////////////////////////////////////////// +// Note: Depaper +////////////////////// +} elseif (args("app") == "depaper") { +echo Welcome("Divide with self using mask"); +///////////////////////////////////////////////////////////////////////// + +$dest = rtrim(args("dir"), '/')."_depaper"; + +if (!file_exists(args("mask"))) { + msg("Can't open mask",1); + } + +if (count(glob($dest."/*.*"))) { + msg("Files already exist in ".$dest.". Move to trash?",2); + exec("/opt/local/bin/trash -a ".$dest); + mkdir($dest); + } elseif (!is_dir($dest)) { + mkdir($dest); + } + +$files = glob(args("dir")."*.*"); +foreach ($files as $file) { + $ext = pathinfo($file,PATHINFO_EXTENSION); + $result = $dest."/".basename($file); + list ($width, $height) = getimagesize($file); + if (substr(basename($file), 0, 3) % 2 == 0) { + $cmd = "convert test.jpg \( ".$file." \( ".args("mask")."[".$width."x".$height."] -rotate 180 \) -alpha Off -compose CopyOpacity -composite \) -compose Over -composite ".$result; + } else { + $cmd = "convert test.jpg \( ".$file." ".args("mask")."[".$width."x".$height."] -alpha Off -compose CopyOpacity -composite \) -compose Over -composite ".$result; + } + $msg = "Converting ".$file; + $thread[] = array($msg, $cmd); + } + +msg("Beginning multithreaded convert with ".$xt." threads"); +multiexec($thread,$xt); + +fin(); + //////////////////////////////////////////////////////////////////////////////////////////////// // Note: Despine ////////////////////// @@ -278,36 +323,6 @@ if (args("levels")) { $adjust = levels_ps_to_imgk("0,250,1"); } -//if (!args("target") || !is_file(args("target"))) { -// msg("Specify a target file to match spine",1); -// } else { -// $target = args("target"); -// } - -//$ext = pathinfo($target,PATHINFO_EXTENSION); -//$tspine_left = "scratch/".basename($target, ".".$ext)."_spineleft.".$ext; -//$tspine_right = "scratch/".basename($target, ".".$ext)."_spineright.".$ext; -//list ($width, $height) = getimagesize($target); -//$even = 0; -//if (substr(basename($target), 0, 3) % 2 == 0) { -// $geo = "+".($width-$swidth)."+0"; -// $cropsize = $swidth."x".$height; -// $crop = $cropsize.$geo; -// $even = 1; -// } else { -// $geo = "+0+0"; -// $cropsize = $swidth."x".$height; -// $crop = $cropsize.$geo; -// } -// -//if ($even) { -// exec("convert ".$target." -crop ".$crop." -flop ".$tspine_left); -// exec("convert ".$target." -crop ".$crop." ".$tspine_right); -// } else { -// exec("convert ".$target." -crop ".$crop." ".$tspine_left); -// exec("convert ".$target." -crop ".$crop." -flop ".$tspine_right); -// } - $files = glob(args("dir")."[0-9][0-9][0-9]-*"); msg("Comparing spines"); @@ -319,27 +334,12 @@ foreach ($files as $file) { $geo = "+".($width-$swidth)."+0"; $cropsize = $swidth."x".$height; $crop = $cropsize.$geo; -// $mytspine = $tspine_right; } else { $geo = "+0+0"; $cropsize = $swidth."x".$height; $crop = $cropsize.$geo; -// $mytspine = $tspine_left; } -// $filespine = "/tmp/".basename($file,$ext)."-spine.".$ext; -// if (!file_exists($filespine)) { -// exec("convert ".$file." -auto-orient -crop ".$crop." ".$filespine); -// } - -// $distance = chop(shell_exec("compare -metric phash ".$mytspine." ".$filespine." /tmp/diffimage 2>&1")); -// if ($distance < $threshold) { -// $print_distance = bashcolor($distance,"green"); -// } else { -// $print_distance = $distance; -// } -// msg("Comparing ".$mytspine." with ".$filespine.": ".$print_distance); - if (args("q")) { $quality = args("q"); } elseif (strtolower($ext) == "jpg") { @@ -348,18 +348,14 @@ foreach ($files as $file) { $quality = $default_quality; } - //if ($distance < $threshold) { - $msg = $file." matched, despining..."; - $cmd = "convert ".$file." \( ".$file." -auto-orient -crop ".$crop." -colorspace gray -level ".$adjust." \) -auto-orient -geometry ".$geo." -compose Divide_Src -composite -quality ".$quality." ".$dest."/".basename($file); - if (args("mix")) { - $pass1 = str_replace("convert", "convert \(", $cmd); - $pass2 = str_replace("-composite", "-composite \) ".$file." -auto-orient -compose dissolve -define compose:args=".args("mix")." -composite", $pass1); - $cmd = $pass2; - } - //} else { - //$msg = $file." "; - //$cmd = "true"; - //} + + $msg = $file." matched, despining..."; + $cmd = "convert ".$file." \( ".$file." -auto-orient -crop ".$crop." -colorspace gray -level ".$adjust." \) -auto-orient -geometry ".$geo." -compose Divide_Src -composite -quality ".$quality." ".$dest."/".basename($file); + if (args("mix")) { + $pass1 = str_replace("convert", "convert \(", $cmd); + $pass2 = str_replace("-composite", "-composite \) ".$file." -auto-orient -compose dissolve -define compose:args=".args("mix")." -composite", $pass1); + $cmd = $pass2; + } $thread[] = array($msg, $cmd); } @@ -694,11 +690,14 @@ $hough = "9x9+200"; foreach ($files as $file) { $ext = pathinfo($file,PATHINFO_EXTENSION); $output = $dest."/".basename($file,$ext)."jpg"; - $msg = "Detecting edges in ".$file; + $msg = "Creating hough composite from ".$file; $cmd = "convert ".$file."[".$size."x".$size."] -auto-orient \( +clone -canny ".$canny." -write /tmp/".basename($file)."_canny.png "; $cmd .= "-background none -fill red -stroke red -strokewidth 1 -hough-lines ".$hough." -write /tmp/".basename($file)."_lines.png \) "; $cmd .= "-composite ".$output; $thread[] = array($msg, $cmd); + $msg = "Creating MVG file from ".$file; + $cmd = "convert /tmp/".basename($file)."_canny.png -hough-lines ".$hough." ".$output.".mvg"; + $thread[] = array($msg, $cmd); } msg("Beginning multithreaded convert with ".$xt." threads"); @@ -1303,24 +1302,34 @@ if (args("pages")) { $pages = false; } -if (!args("map")) { - msg("No brightness map specified",1); - } elseif (!file_exists(args("map"))) { +if (!file_exists(args("map"))) { msg("Can't open brightness map",1); - } elseif (substr(args("map"), -3, 3) == "JPG") { - //$method = "auto-level"; - $method = "normalize"; - $map = "scratch/".basename(args("map"),".JPG")."-divide_map.tif"; - if (!file_exists($map)) { - @exec("convert -".$method." -colorspace gray ".args("map")." ".$map); - } - } elseif (substr(args("map"), -3, 3) == "jpg" | substr(args("map"), -3, 3) == "tif") { - $map = args("map"); } - -if (args("mpush")) { - $map = basename(args("map"),".JPG")."-pushed.tif"; - @exec("convert -level ".levels_ps_to_imgk(args("mpush"))." ".args("map")." ".$map); + +$ext = pathinfo(args("map"), PATHINFO_EXTENSION); +if (strtolower($ext) == "tif" && !args("mpush")) { + $map = "scratch/".args("map"); + copy(args("map"),$map); + } else { + $map = "scratch/".basename(args("map"),".".$ext)."-divide_map.tif"; + $cmd = "convert -colorspace gray "; + if (args("mpush") == "auto") { + $cmd .= "-normalize "; + } elseif (args("mpush")) { + $cmd .= "-level ".levels_ps_to_imgk(args("mpush"))." "; + } + $cmd .= args("map")." ".$map; + msg("Converting map..."); + @exec($cmd); + } + +if ($pages) { + $ext = pathinfo($map, PATHINFO_EXTENSION); + $mapleft = str_replace(".".$ext, "-left.tif", $map); + $mapright = str_replace(".".$ext, "-right.tif", $map); + msg("Making map pages..."); + @exec("convert -rotate 90 -flip ".$map." ".$mapleft." 2>&1"); + @exec("convert -rotate 270 ".$map." ".$mapright." 2>&1"); } $dest = rtrim(args("dir"), '/')."_divided"; @@ -1339,15 +1348,6 @@ if (args("q")) { $quality = 95; } -if ($pages) { - $ext = pathinfo($map, PATHINFO_EXTENSION); - $mapleft = "scratch/".str_replace(".".$ext, "_left.".$ext, $map); - $mapright = "scratch/".str_replace(".".$ext, "_right.".$ext, $map); - //@exec("convert -rotate 90 -quality 95 ".$map." ".$mapleft." 2>&1"); - @exec("convert -rotate 90 -flip -quality 95 ".$map." ".$mapleft." 2>&1"); - @exec("convert -rotate 270 -quality 95 ".$map." ".$mapright." 2>&1"); - } - echo "Building threads: "; $thread = array();