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

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
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

You need the exclamation mark, "!". See http://www.imagemagick.org/script/comma ... p#geometry
snibgo's IM pages: im.snibgo.com
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

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

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

I don't understand the question. You could "-resize x1000" which would keep the aspect ratio, so the result is 1500x1000 pixels.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

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

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
Post Reply