Page 1 of 1

Resize on largest side

Posted: 2009-02-20T10:10:38-07:00
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

Re: Resize on largest side

Posted: 2009-02-20T11:07:14-07:00
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

Re: Resize on largest side

Posted: 2009-02-21T17:04:50-07:00
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...

Re: Resize on largest side

Posted: 2009-02-21T18:32:02-07:00
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

Re: Resize on largest side

Posted: 2009-02-22T03:57:15-07:00
by mrgou
Alright! Thanks, that's it! :D

Re: Resize on largest side

Posted: 2014-01-09T11:49:05-07:00
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

Re: Resize on largest side

Posted: 2014-01-09T13:47:20-07:00
by snibgo
Can you be more specific? "-resize 1024x768" will ensure the image fits within a rectangle 1024x768.

Re: Resize on largest side

Posted: 2014-01-09T17:31:15-07:00
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.