rgareth
rgareth

Reputation: 3526

Batch crop images to fixed height (CLI)

I have images of variable height and width, and I want to crop them all to be 200 pixels high, without any resizing. i.e. their width will remain the same, and height will be 200px. I want to use "north" gravity for this.

Any CLI tool that allows batch processing would be OK - imagemagick/mogrify, gm, etc. I've tried to figure this out but can't find any option to just leave width unspecified.

Upvotes: 0

Views: 304

Answers (2)

emcconville
emcconville

Reputation: 24419

mogrify *.png -gravity North -extent x200 -path ./complete

The mogrify utility would suite your batch task with -gravity, -extent, and -path options:

Upvotes: 1

Wander Nauta
Wander Nauta

Reputation: 19615

You could leave the width unspecified by, well, leaving the width unspecified, and use extent to do the cropping:

convert in.png -extent x200 out.png

or, say,

mogrify -extent x200 *.png

For the wizard example image, that would turn this into this. You can see more resizing examples on the examples site, as well as some different ways of doing cropping.

Upvotes: 1

Related Questions