Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick - how to enforce min/max heights/widths?

Using ImageMagick, how can I resize an image to have a minimum:

  • height of 150px
  • width of 200px

and also have a maximum:

  • height of 225px
  • width of 275px

UPDATE:

In case it helps, here's a further explanation of what I'm experiencing.

I have a buch of images with all different ratio dimensions. Some images have 1:5 height/width ratios. Some have 5:1 height/width ratios. So that I want to do is set that a minimum height/width size for the image but also don't want the image size to be larger than a particular size.

If I need to apply white padding to an image to make it fit within my constraint so that I don't have to distort the image, I'd like to do so.

like image 586
Henryh Avatar asked May 06 '10 16:05

Henryh


1 Answers

I can't entirely get my head around your requirement, but I think this should be possible if you run IM twice.

See the manual on geometry options:

A combination of

widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.

and

widthxheight^ Minimum values of width and height given, aspect ratio preserved.

might do the trick. However, for images whose aspect ratio lies outside your requirements, I think you will have to create a fixed size canvas in IM, fill it with some colour, insert the image, and do a trim() on it... Probably not possible in one go, though.

like image 185
Pekka Avatar answered Sep 23 '22 17:09

Pekka