Ensure minimum and maximum height of thumbnail

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
rivarola
Posts: 4
Joined: 2015-06-03T09:57:55-07:00
Authentication code: 6789

Ensure minimum and maximum height of thumbnail

Post by rivarola »

Hello,

I have an input image with dimensions 160xY, and I want to resize it to 160xH, where H between 128 and 213 pixels.
If Y is more than 213, I want to cut the bottom of the image.
If Y is less than 128, I want to add transparent margin at top and bottom of the original image.
I tried

Code: Select all

convert input.jpg -background none -gravity North -crop 160x213+0+0 -gravity Center -extent "x128<" ouput.png
but it cuts all images to exactly 128 pixels height :( . The same with -extent "x128^".

Is it a bug on the extent option ? How perform such a transformation ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Ensure minimum and maximum height of thumbnail

Post by snibgo »

As far as I know, "-extent" always gives the requested size, and is never conditional on whether this would shrink or enlarge the dimensions.

So if you are using "-extent", it needs to be within a script conditional. You could do it in a single command by creating a canvas 160x128 and compositing over this canvas.
snibgo's IM pages: im.snibgo.com
rivarola
Posts: 4
Joined: 2015-06-03T09:57:55-07:00
Authentication code: 6789

Re: Ensure minimum and maximum height of thumbnail

Post by rivarola »

Thanks, I'll try it.
Post Reply