Page 1 of 1

Ensure minimum and maximum height of thumbnail

Posted: 2015-06-05T01:36:44-07:00
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 ?

Re: Ensure minimum and maximum height of thumbnail

Posted: 2015-06-05T03:07:13-07:00
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.

Re: Ensure minimum and maximum height of thumbnail

Posted: 2015-06-05T03:25:18-07:00
by rivarola
Thanks, I'll try it.