Processing scanned documents - adjusting the margines
Post ReplyProcessing scanned documents - adjusting the marginsPosted: Sunday, April 21, 2024 [22:34:00] - 1
When dealing with scanned documents featuring unconventional margins, adjustments become necessary. Whether due to scanning errors or formatting inconsistencies, these irregularities can disrupt the readability and presentation of the document. ![]() To rectify this issue, one effective solution is to utilize ImageMagick, a powerful command-line tool for image editing and manipulation. use warnings; use File::Basename qw(); # Name this Perl file as folder where images are stored adding distinct process name as "image_process" # this way it is easy to get images folder based on file name # in this case there is no need to hard-code folder names # program can be run in full or relative file call i.e. perl your.images.image_process.cgi or .pl my($name, $base, $suffix) = File::Basename::fileparse($0); $base =~ s/\/+$//; $name =~ s/\.\w{2,3}$//; print "Name: $name\nPath: $base\n"; # Remove the file name addition $name =~ s#\.image_process$##; # Folder where image files are my $from = $base.'/'.$name.'.images'; # Get all image files in a folder, adjust file extension to your files my @all = glob("$from/*.tif"); foreach my $i (@all) { # Get the trim values if the image is trimmed my $res = `convert $i +repage -trim -format '%[fx:page.width] %[fx:page.x] %[fx:page.width - page.x - w] %[fx:w]' info:`; my($width,$left_trim,$right_trim,$new_width) = split(/ /,$res); # $width - width of the image before trim # $left_trim - how many pixels trimmed from image left side # $right_trim - how many pixels trimmed from image right side # $new_width - image width after trim is performed # .. do your image processing based on data received } Document has to be quite clean in order for this to work, i.e. no punch holes on a side. |