Bulk crop images based on CSV input.

Jakub Valenta c673edbd4c Add option --preserve-timestamp, -t 3 months ago
.gitignore 180237c4ae Initial commit 3 months ago
LICENSE 180237c4ae Initial commit 3 months ago
NOTICE 1e1a474d20 Add everything 3 months ago
README.md a03e05574c README: Fix quotes in cmd examples 3 months ago
image_crop c673edbd4c Add option --preserve-timestamp, -t 3 months ago

README.md

Image Crop

Bulk crop images based on CSV input.

Installation

Required Python version: 3.3 or higher.

Required packages:

Required Python packages:

pip install click

Usage

Image Crop takes a space-separated CSV file as its input in the following format:

<FILE_PATH> <OFFSET_LEFT_PX> <OFFSET_TOP_PX> <WIDTH_PX> <HEIGHT_PX>
<FILE_PATH> <OFFSET_LEFT_PX> <OFFSET_TOP_PX> <WIDTH_PX> <HEIGHT_PX>
...

The CSV is then read from the standard input (stdin).

Internally, Image Crop will run GraphicsMagic in the following format:

gm convert "<FILE_PATH>" -crop <WIDTH_PX>x<HEIGHT_PX>+<OFFSET_LEFT>+<OFFSET_TOP> "<FILE_BASENAME>__crop.<FILE_EXT>"

Example

echo '"My Images/DSC-123.JPG" 5 10 600 350' | ./image_crop

Resulting GraphicsMagic call:

gm convert "My Images/DSC-123.JPG" -crop 600x350+5+10 "My Images/DSC-123__crop.JPG"

More options

--suffix, -s: File name suffix, defaults to "__crop"

--resize-width, -rw: Resize the resulting image to exactly this width, optional.

--resize-height, -rh: Resize the resulting image to exactly this height, optional.

If only one of --resize-width or --resize-height options are passed, then the other dimension will be calculated in such a way, that the original image aspect ratio is preserved.

Example

echo '"My Images/DSC-123.JPG" 5 10 600 350' | ./image_crop --suffix "-mod" -rw 1080

Resulting GraphicsMagic call:

gm convert "My Images/DSC-123.JPG" -crop 600x350+5+10 -resize 1080x "My Images/DSC-123-mod.JPG"

Help

./image_crop --help

Contributing

Feel free to remix this piece of software. See NOTICE and LICENSE for license information.