diff --git a/leaf.php b/leaf.php index 933beb9..41c0898 100644 --- a/leaf.php +++ b/leaf.php @@ -1,7 +1,7 @@ (20) levels attenuation -size= (2200) dmap size in pixels -nomap don't use dmaps -depaper divide page with itself using mask (better despine) +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-2,0-255\") -mix=<0-100> (null) percentage mix with original (90% = mostly og) @@ -247,6 +288,9 @@ generate create final jpg images for pdf creation -pt=<0-255> use threshold method with photoshop level value -pc=<2,2!,3> (2) colors for final png (2! = intermediary dithering) -unsharp= photoshop unsharp parameters (ex. \"100,1,0\") + -skipc skip color images + -skipg skip grayscale images + -skipb skip bitmap images match move files and set crop values to match source dir -source= read FROM dir notes save leaf shell history to text file @@ -271,6 +315,67 @@ strip strip exif crop values from images with exiftool echo $help; fin(); +foreach ($picks as $file) { + $parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom ".$file." 2>&1")); + @list($top, $right, $left, $bottom) = explode("\n", $parts); + if ($top && $right && $left && $bottom) { + $key = filter_var(substr(basename($file), 4), FILTER_SANITIZE_NUMBER_INT); + $crops[$key]['top'] = $top; + $crops[$key]['right'] = $right; + $crops[$key]['left'] = $left; + $crops[$key]['bottom'] = $bottom; + } else { + msg("Problem reading crops from file ".$file.". Continue?",2); + } + } + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Note: Autocrop +////////////////////// +} elseif (args("app") == "autocrop") { +echo Welcome("Crop using row/column brightness method"); +///////////////////////////////////////////////////////////////////////// + +msg("Checking crops"); + +$files = glob(args("dir")."*.*"); +foreach ($files as $file) { + + $parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom ".$file." 2>&1")); + @list($top, $right, $left, $bottom) = explode("\n", $parts); + echo "\nExisting crop values for ".$file.": "; + echo "\tTop: ".bashcolor($top, "light blue"); + echo "\tRight: ".bashcolor($right, "light green"); + echo "\tLeft: ".bashcolor($left, "light cyan"); + echo "\tBottom: ".bashcolor($bottom, "light red"); + + $detectx = explode("\n",chop(shell_exec("convert \( $file +repage -scale x1! -bordercolor black -border 1 -fuzz 30% -trim \) -format \"%w\n%O\" info:"))); + $detecty = explode("\n",chop(shell_exec("convert \( $file +repage -scale 1x! -bordercolor black -border 1 -fuzz 60% -trim \) -format \"%h\n%O\" info:"))); + $detectxparts = explode("+", $detectx[1]); + $detectyparts = explode("+", $detecty[1]); + + list($ntop, $nright, $nleft, $nbottom) = crop_imgk_to_xmp($detectx[0], $detecty[0], $detectxparts[1], $detectxparts[2]); + + echo "\nNew crop values for ".$file.": "; + echo "\tTop: ".bashcolor($ntop, "blue"); + echo "\tRight: ".bashcolor($nright, "green"); + echo "\tLeft: ".bashcolor($nleft, "cyan"); + echo "\tBottom: ".bashcolor($nbottom, "red"); + + $msg = "Setting crop values for ".$file; + $cmd = "exiftool -overwrite_original -XMP-crs:HasCrop=1 -XMP-crs:AlreadyApplied=0 -XMP-crs:CropTop=".$ntop." -XMP-crs:CropRight=".$nright." -XMP-crs:CropLeft=".$nleft." -XMP-crs:CropBottom=".$nbottom." ".$file; + + $thread[] = array($msg, $cmd); + + echo "\n".$msg; exec($cmd); + + } + +//msg("Write crop values?",2); +//multiexec($thread,$xt); + +fin(); + //////////////////////////////////////////////////////////////////////////////////////////////// // Note: Notes ////////////////////// @@ -1377,8 +1482,8 @@ echo Welcome("Combine finished images into a pdf with python img2pdf"); $input = args("dir")."*.*"; $dest = basename(getcwd()).".pdf"; if (file_exists($dest)) { - $dest = basename(getcwd())."_".rand(1000,9999).".pdf"; - if (file_exists($dest)) { msg("Freak accident",1); } + msg("Files ".$dest." already exists. Move to trash?",2); + exec("/opt/local/bin/trash -a ".$dest); } echo "Creating pdf...\n\n"; exec("img2pdf --verbose --viewer-page-layout twocolumnright --author 'Leaf ".$version."' --output ".$dest." ".$input); @@ -1687,25 +1792,12 @@ if (!args("nomap")) { if (!file_exists($dmfile)) { - $parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom -ImageWidth -ImageHeight ".$file." 2>&1")); - @list($top, $right, $left, $bottom, $check_width, $check_height) = explode("\n", $parts); - if (!$top || !$right || !$left || !$bottom) { msg($file." missing crop information!",1); } - - $jpeg_width = $check_height; - $jpeg_height = $check_width; - - $top_pixels = floor( $jpeg_width * $top ); - $right_pixels = $jpeg_height - floor( $right * $jpeg_height ); - $left_pixels = floor( $jpeg_height * $left ); - $bottom_pixels = $jpeg_width - floor( $bottom * $jpeg_width ); - - $width = $jpeg_width - ( $top_pixels + $bottom_pixels ); - $height = $jpeg_height - ( $left_pixels + $right_pixels ); - - $area_left = ( $width + $deskew_padding*2 )."x".( $height + $deskew_padding*2 )."+".( $bottom_pixels - $deskew_padding )."+".( $left_pixels - $deskew_padding ); - $area_right = ( $width + $deskew_padding*2 )."x".( $height + $deskew_padding*2 )."+".( $top_pixels - $deskew_padding )."+".( $right_pixels - $deskew_padding ); - - //echo "\n\n(Area left = ".$area_left.", Area right = ".$area_right.")"; + $parts = chop(shell_exec("exiftool -s -s -s -XMP-crs:CropTop -XMP-crs:CropRight -XMP-crs:CropLeft -XMP-crs:CropBottom -ImageWidth -ImageHeight -Orientation ".$file." 2>&1")); + $getcrop = crop_xmp_to_imgk($parts,$deskew_padding); + + if (!$getcrop) { + msg($file." missing crop or orientation information!",1); + } $size = $deskew_size."x".$deskew_size; @@ -1715,11 +1807,7 @@ if (!args("nomap")) { $adj = $deskew_contrast."%,".(100-$deskew_contrast)."%"; } - if (substr(basename($file), 0, 3) % 2 == 0) { - $cmd = "convert ".$file." -auto-orient -crop ".$area_right." -level ".$adj." -colorspace Gray -resize ".$size." ".$dmfile; - } else { - $cmd = "convert ".$file." -auto-orient -crop ".$area_left." -level ".$adj." -colorspace Gray -resize ".$size." ".$dmfile; - } + $cmd = "convert ".$file." -auto-orient -crop ".$getcrop." -level ".$adj." -colorspace Gray -resize ".$size." ".$dmfile; $msg = "Creating dmap for ".$file; $thread[] = array($msg, $cmd); @@ -1861,11 +1949,5 @@ echo Welcome("Program name \"".$argv[1]."\" not found"); ///////////////////////////////////////////////////////////////////////// die; - -// check bridge labels -// for i in *; do exiftool -s -s -s -Label $i; done - -// convert to sRGB lossy -// jpegicc -q100 001-Plustek0001.jpg 001-Plustek0001_out.jpg ?> \ No newline at end of file