How can I resize to fixed dimensions?

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
adamsilver
Posts: 3
Joined: 2013-03-24T20:49:57-07:00
Authentication code: 6789

How can I resize to fixed dimensions?

Post by adamsilver »

Hello,

I searched a lot and I couldn't figure out how to achieve the following:

I have a news aggregation service so I am getting images of various dimensions. I have to create a 3 versions of the aggregated story image:

50x50, 150x100 and 278x209.

The dimensions must be absolutely what's mentioned above.

I currently have this:

Code: Select all

convert {input} -resize {dimensions} {output}
But sometimes my specified dimensions are not being strictly adhere to, I don't know why.

I don't want to end up with deformed images either if I prevent images from scaling proportionally.

What are my options?

Your help would be appreciated.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: How can I resize to fixed dimensions?

Post by GreenKoopa »

If, for example, you want to create a 50x50 image from a 100x124 image, you can:
  • resize it to 40x50 (what you are probably doing now)
  • resize it to 40x50, then add margins (of any color, maybe even transparency) to 50x50
  • resize it to 50x62, then crop it to 50x50
  • squish it into 50x50, causing some distortion
Which option would you like?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I resize to fixed dimensions?

Post by anthony »

Also see Resize Flag 'no aspect'
http://www.imagemagick.org/Usage/resize/#noaspect

The other resize flags in that same area may also be useful..

But you need to be clear about exactly what you are wanting for us to help you further.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply