Page 1 of 1

Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-03T14:45:45-07:00
by helloworld
Hello All,

Actually, I am trying to resize a image whose width and height are "18200x12133" to "1050x1500" and i am using the command,

convert original.jpg -resize 1050x1500 resized.jpg

When i go and checked the dimensions of the converted image its showing me 1050x700. I am not sure why i am not getting the exact width and height which i required

For your reference, I am placing the used original and resized image in the dropbox, you can download those from below links,
https://www.dropbox.com/s/2uhmqhjjimg4e51/original.jpg
https://www.dropbox.com/s/owtytwn8kh9oh6r/resized.jpg

The Version and Delegates which are installed on my server is,

Version: ImageMagick 6.8.5-7 2013-06-22 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib djvu fontconfig freetype jng jp2 jpeg lcms lqr openexr pango png ps tiff x xml zlib


-- Helloworld

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-03T15:26:21-07:00
by snibgo
You need the exclamation mark, "!". See http://www.imagemagick.org/script/comma ... p#geometry

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-03T17:59:35-07:00
by helloworld
Thanks for the link Snibgo. It helped me.

Now i have another question, actually i am looking for an aspect ratio not the exact width and height. So i have a image "18200x12133" and trying to resize it to "1050x1500" with an aspect ratio. But when i am doing an aspect ratio resizing there should only be slight change like 2 to 10pixels but not like 500 pixels right?

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-03T19:09:33-07:00
by snibgo
I don't understand the question. You could "-resize x1000" which would keep the aspect ratio, so the result is 1500x1000 pixels.

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-03T19:10:47-07:00
by fmw42
resizing to 1050x1500 will preserve the input image aspect ratio by scaling the larger dimension to 1500 and the smaller dimension will be 1500 or smaller depending upon the actual input image aspect ratio.

Your input aspect ratio is w/h=18200/12133=1.5=3:2 Thus if you specify 1500x1500, you will get 1500x1000 since that is 3:2.

If you want a different aspect ratio, then you will have to either pad or crop or distort the image.

see
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/thumbnails/#pad
http://www.imagemagick.org/Usage/thumbnails/#cut

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-04T08:18:18-07:00
by helloworld
Thanks for the explanation.

So according to your calculation, when i resized a image whose width and height 18200x12133 to 1050x1500 with an aspect ratio i should get a image which has 1050 width and 1000 height but i am getting a image whose width is 1050 and height is 700. I don't know why i am getting 1050x700 instead of 1050x1000

If you want the original and resized images are on the below links,
https://www.dropbox.com/s/2uhmqhjjimg4e51/original.jpg
https://www.dropbox.com/s/owtytwn8kh9oh6r/resized.jpg

--HelloWorld

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-04T08:41:14-07:00
by snibgo
Sorry I still don't understand your question.

Your input image is wider than it is tall. If you want to keep the same aspect ratio, the output will also be wider than it is tall. You can't keep the same aspect ratio AND make it taller than is it wide.

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-04T12:28:02-07:00
by helloworld
I figured it out and the problem is on my end.

Ok lets ask you one more question, Is there any way to find whether the image is Landscape or Portrait before cropping it?

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-04T14:58:56-07:00
by snibgo
You can find out if the height is greater than the width. For example ...

Code: Select all

convert rose: -format "%[fx:h>w]" info:
... outputs 0 or 1.

Re: Problem in Resizing a image to a fixed width and height.

Posted: 2013-12-04T15:33:59-07:00
by fmw42
Sorry I misread your sizes. I thought you said 1500x1500 and not 1050x1500

Since your input has a ratio of 3:2, then the output will be scaled so that the larger dimension (in this case width) becomes 1050 and the other dimension will scale to 1050*2/3=700, which is exactly what I get when I resize according to your command.


If you are on Linux/Mac or Windows with Cygwin, you might find one of my scripts that will do what you want? See aspect, aspectcrop and aspectpad at the link below.