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?
Batch-cropping the 20 lowermost pixels away from .jpgs
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch-cropping the 20 lowermost pixels away from .jpgs
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Batch-cropping the 20 lowermost pixels away from .jpgs
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Batch-cropping the 20 lowermost pixels away from .jpgs
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.