How to resize image more intelligently?

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
lakershen

How to resize image more intelligently?

Post by lakershen »

I am new to ImageMagick. Try to resize image for my web users on the fly. Here's what I want:

if the shape of image is width > length, resize it and make the width as 50.
if the shape of image is length > width, resize it and make the length as 50.

I understand ImageMagick convert commant can take either width or length and set the other value proportionally. However, seems there's no way to do this kind of smart resize directly.

How to solve the problem?

thanks!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to resize image more intelligently?

Post by anthony »

Which IM has some IF constructs in say a -rotate command, That is if landscape make it protrait before doing the resize, It can't tell later if it should rotate the image back again! Not unless some exif attribute is updated by the normal rotate.

Basically you are asking to much of the command line operation sequence, whcih has no IF-ELSE construct.

You will need to identify the image first and then pick the right convert command,
or use an API like PerlMagick that can make desicions in the middle of a operation sequence.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lakershen

Re: How to resize image more intelligently?

Post by lakershen »

Thanks. Fair enough.

Not sure how exactly imagemagick works. It should not be too hard to add this smart convert command to resize the image. I think a lot of users should have similar request. Unfortunately, I am using java to build my website. Maybe I have to use the java native image library, although it requires a lot of memory.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to resize image more intelligently?

Post by glennrp »

convert -resize 50x50
should do exactly what you want.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to resize image more intelligently?

Post by anthony »

Oh yes of course. you are resizing the LONGEST length, do just resize it to a box 50x50.

Sorry, I was in a frame of mind from another request that had two complely different sizes depending on the whether the image is landscape or portrait, which is a definate IF-ELSE construct. That is not the case here. Appoliges.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply