Bulk Cropping Pictures

Pierre-Louis Blanchard

Bulk Cropping Pictures

If you take a series of pictures taken with a tripod, for example photos of a document, you might have a part of the pictures you want to crop on every picture.

Instead of doing this manually in a picture editor, you can do this on the command line by writing a simple script to do that.

Prerequisite: batch_crop, available in the package libvips.

How to do it

First, put all files you want to crop in a file. For example like this:

$ ls -1 > crop.sh

This will print all file names in the present directory into a file called "crop.sh" in a single column. Then we will use this file to create a file like this, where the numbers behind "batch_crop" stand for coordinates where to crop each picture. I got these coordinates by using the program "mirage" and using the crop function there without doing the cropping there. In the end, run the script and the pictures will be cropped. The pictures will be prefixed with "cropped" to indicate the changed files. Thus, your original files are not overwritten.

#!/usr/bin/env sh

batch_crop 31 1517 1961 1476 20210624_132930.jpg
batch_crop 31 1517 1961 1476 20210624_132954.jpg
batch_crop 31 1517 1961 1476 20210624_133015.jpg
batch_crop 31 1517 1961 1476 20210624_133034.jpg
batch_crop 1187 1084 1909 1579 20210624_133052.jpg
batch_crop 1187 1084 1909 1579 20210624_133104.jpg
batch_crop 1187 1084 1909 1579 20210624_133111.jpg
batch_crop 1187 1084 1909 1579 20210624_133118.jpg
batch_crop 1187 1084 1909 1579 20210624_133125.jpg
batch_crop 1187 1084 1909 1579 20210624_133130.jpg
batch_crop 1187 1084 1909 1579 20210624_133146.jpg
batch_crop 1187 1084 1909 1579 20210624_133202.jpg
batch_crop 1187 1084 1909 1579 20210624_133206.jpg
batch_crop 1187 1084 1909 1579 20210624_133212.jpg
batch_crop 1187 1084 1909 1579 20210624_133217.jpg
batch_crop 1187 1084 1909 1579 20210624_133223.jpg
batch_crop 1187 1084 1909 1579 20210624_133232.jpg
batch_crop 1187 1084 1909 1579 20210624_133238.jpg
batch_crop 1187 1084 1909 1579 20210624_133247.jpg
batch_crop 1187 1084 1909 1579 20210624_133255.jpg
batch_crop 1187 1084 1909 1579 20210624_133304.jpg
batch_crop 1187 1084 1909 1579 20210624_133310.jpg

Pierre-Louis Blanchard, 25. june 2021


← I’m scared. Take me back HOME!


Last updated on: 2024-05-20