Mogrify height only

Forum rules
Before you post please read how to get help
Level 1
Level 1
Posts: 45
Joined: Fri Jan 09, 2009 7:22 am

Mogrify height only

Postby Nevart » Thu Jun 21, 2012 11:38 am

Is there some way to mogrify images so that only the y axis (height) of the image is factored?

So what I mean is if I have say 20 images and they are all like:

1.jpg = 1024 x 768
2.jpg = 568 x 337
3.jpg = 290 x 560

It's fairly easy to make all of these be 500px wide and maintain the current aspect ratio by doing this:

mogrify -resize 500 *.jpg

or if I want to make them all 500 x 468 then I can do this

mogrify -resize 500x468 *.jpg

but I can't figure out how I can reset the height of all the images to (for example) 468 and retain the same aspect ratio, where all the images are already different sizes. I'd really like to know how to do it so does anybody know if this is possible?

I don't have my hopes up, and it would be quicker for sure to do all this in GIMP rather than waiting for a reply, but y'know, for the benefit of future generations and all that...

User avatar
Level 24
Level 24
Posts: 21643
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Mogrify height only

Postby xenopeek » Fri Jun 22, 2012 4:25 am

Moved here by moderator

I use ImageMagick instead. Install the package "imagemagick" with the Software Manager, or run:

Code: Select all

sudo apt-get install imagemagick

Open a terminal on the directory where you have your images, and run:

Code: Select all

convert *.jpg -scale x500 new.jpg

This scales all the images to a fixed height of 500 pixels, scaling the width dynamically to maintain the aspect ratio of the image. It creates files called new-0.jpg, new-1.jpg, new-2.jpg and so on. If you want some more control over the name, use a loop:

Code: Select all

for name in $(ls *.jpg); do
   convert $name -scale x500 $

This adds the extension ".new.jpg" to the end of the original filename.

Return to “Scripts & Bash”