Resize on largest side

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mrgou

Resize on largest side

Post by mrgou »

Hi,

With convert, how can I resize an image with the shortest side to a specified target size, whichever side happens to be the shortest?

I'm trying to do this in a batch file, so that the original size of a given picture is unknown. Basically, I want to resize all images in a folder so that the shortest side will be 2000 pixels.

Additionally, can I make it ignore a resize if the image is already smaller than the specified resize?

Thanks!

Raph
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize on largest side

Post by fmw42 »

mrgou wrote:Hi,

With convert, how can I resize an image with the shortest side to a specified target size, whichever side happens to be the shortest?

I'm trying to do this in a batch file, so that the original size of a given picture is unknown. Basically, I want to resize all images in a folder so that the shortest side will be 2000 pixels.

Additionally, can I make it ignore a resize if the image is already smaller than the specified resize?

Thanks!

Raph
see the ^ and the > characters use in resize at http://www.imagemagick.org/script/comma ... p#geometry

examples at http://www.imagemagick.org/Usage/resize/#resize

If you are on windows, see escapes, etc at http://www.imagemagick.org/Usage/api/#windows
mrgou

Re: Resize on largest side

Post by mrgou »

Thanks. I saw that, but to be honest, I don't quite understand how to use it :? . What is the combination I need to use so that the shortest size will be 2000, when and only when the image will have to be reduced. As a result, the longest side should always be larger than 2000, and I don't manage to get this. Some of my pictures will be portrait, some landscape, and I was hoping to find a command that would reduce based on the largest side, whichever it is...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize on largest side

Post by fmw42 »

mrgou wrote:Thanks. I saw that, but to be honest, I don't quite understand how to use it :? . What is the combination I need to use so that the shortest size will be 2000, when and only when the image will have to be reduced. As a result, the longest side should always be larger than 2000, and I don't manage to get this. Some of my pictures will be portrait, some landscape, and I was hoping to find a command that would reduce based on the largest side, whichever it is...

To resize smaller side to 100 if it is larger than 100 and preserve aspect ratio, use

convert image.jpg -resize "100^>" newimage.jpg

To resize larger side to 100 if it is larger than 100 and preserve aspect ratio, use

convert image.jpg -resize "100>" newimage.jpg
mrgou

Re: Resize on largest side

Post by mrgou »

Alright! Thanks, that's it! :D
saywell
Posts: 1
Joined: 2014-01-09T11:45:59-07:00
Authentication code: 6789

Re: Resize on largest side

Post by saywell »

Just to take this further, I need a command that will resize larger images to fit 1024 x 768. So 'larger side' will vary according to whether it's landscape or portrait orientation.

How can I do this? Haven't found anything in the help or examples.

Thanks.

William
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize on largest side

Post by snibgo »

Can you be more specific? "-resize 1024x768" will ensure the image fits within a rectangle 1024x768.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize on largest side

Post by fmw42 »

I believe that you need to compute and test the aspect ratio (w/h) to see if it is landscape or portrait. Then use -resize "1024x768>" if landscape and -resize "768x1024>" if portrait.

see my script, aspect, at the link below, though it does the resize always. It does not have a size limit flag in it. But it could be added.
Post Reply