Search code examples
imageimage-processingautomationcrop

Automating the cropping of many large image files


I have two thousand large (20mb) image files. Each file has the same height, width, and resolution. The files are currently JPGs, though they are available in other formats.

For each image, I need to extract 6 cropped images from the larger file, each of which are in exactly the same location across the larger files.

I am looking to provide the coordinates of the regions I need extracted (or that I need each larger image cropped to) and then to loop through all 2,000 of the larger images and extract the size sub-images (specified by coordinates), from the larger images.

Is there a program, software package, or straight forward way to do this in python, Java, or some other language?


Solution

  • It seems that ImageMagick is exactly what you need.

    ImageMagick has interfaces for Python, C and C++, Perl and Java. See full list of APIs on the page: http://www.imagemagick.org/script/api.php

    Also uou can use mogrify utility (often comes with ImageMagick package), which can process images massively. Then your command line might look like this:

    mogrify -crop 420x400+365+25 -path '/home/user/images' *.jpg