Mogrify height only

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Nevart

Mogrify height only

Post by Nevart »

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...
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29612
Joined: Wed Jul 06, 2011 3:58 am

Re: Mogrify height only

Post by xenopeek »

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 $name.new.jpg
done
This adds the extension ".new.jpg" to the end of the original filename.
Image
Locked

Return to “Scripts & Bash”