Page 1 of 1

Batch-cropping the 20 lowermost pixels away from .jpgs

Posted: 2012-01-25T04:59:38-07:00
by nrabett
I have a large collection of book pages in .jpg format, and I want to perform a batch-cropping operation where the 20 lowermost lines of pixels are removed without altering the rest of the picture. This is important because these pixels contain dark areas which complicate post-processing with Scan Tailor.

Today, I use the lossless batch-cropping tool JPEGCrops for this, but there are several disadvantages with this approach. The originals have slightly different pixel sizes, and JPEGCrops only accepts batch-cropping to a single, preset pixel value. Thus, in order to successfully batch-crop the images, I have to choose pixel sizes that might be too small for the bigger ones of the originals. Furthermore, the JPEGCrops crop box is apparently always placed in the middle of the image.

There must be an easier way, involving a simple script and ImageMagick. But how?

Re: Batch-cropping the 20 lowermost pixels away from .jpgs

Posted: 2012-01-25T14:51:54-07:00
by fmw42
Use mogrify with -chop

create a new directory to hold the processed images, say test2, and assume your images are in test1

cd test1
mogrify -path /path2/test2 -format jpg -gravity south -chop 0x20 *.jpg

see
http://www.imagemagick.org/Usage/crop/#chop
http://www.imagemagick.org/Usage/basics/#mogrify

Re: Batch-cropping the 20 lowermost pixels away from .jpgs

Posted: 2012-01-25T21:14:15-07:00
by anthony
Warning reading in and writing out JPEG will slighty degrade the image -- that is the nature of JPEG.

However their are a few JPEG crop methods (limited to 8 or 16 pixel boundaries) that will not degrade the image format, just manipulate the JPEG 'cell data'. It is not however a pleasant technique.

http://www.imagemagick.org/Usage/formats/#jpg_lossless

If quality is not a concern then what Fred described about, using IM, is fine and easy to do.

Re: Batch-cropping the 20 lowermost pixels away from .jpgs

Posted: 2012-02-17T03:23:47-07:00
by nrabett
Many thanks for the answers. A small update: Although I am not sure how it is done, JPEGCrops does batch-cropping to any pixel size and claims that this is done without quality loss. The easiest way of achieving what I wanted, turned out to use Irfanview Thumbnails in order to sort the images according to pixel size, find the image with the lowest pixel values, and adjust settings in JPEGCrops accordingly.