Page 1 of 1

Resizing image to a dimension

Posted: 2014-08-28T10:30:34-07:00
by osnsubra
Hi, We have our images in PNG format with 750x1050 dimension. We want to resize the images to a dimension 180x340, and the following command is not converting to the exact dimension, rather its covnerting to 180x250.

Command used: convert -resize 180x340

We have also used various options like : –trim –geometry 180x340! -resize 180x340, which is stretching the image.

Pls let me know the right command to convert the image to this desired format. Appreciate your response.

Re: Resizing image to a dimension

Posted: 2014-08-28T10:32:54-07:00
by snibgo
convert in.png -resize 180x340! out.png

See http://imagemagick.org/script/command-l ... php#resize , and the link to Image Geometry.

Re: Resizing image to a dimension

Posted: 2014-08-28T10:45:39-07:00
by osnsubra
I have tried the following command., and its stretching the image to vertical. Basically its a Wine bottle image, i thought of attaching here but there is no option to attach image in this forum.

convert in.png -resize 180x340! out.png

Re: Resizing image to a dimension

Posted: 2014-08-28T11:20:37-07:00
by snibgo
Well, that's what you said you wanted.
We want to resize the images to a dimension 180x340, ...
You can upload files to somewhere like dropbox.com and paste the URL here.

Re: Resizing image to a dimension

Posted: 2014-08-28T11:49:10-07:00
by fmw42
180x340!
Using the ! tells IM to ensure that the size is exactly as specified even if it distort the image. If you want no distortion and aspect ratio preserved, either leave it off and pad or use ^ and crop or extent. See

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

see various options at
http://www.imagemagick.org/Usage/crop/
http://www.imagemagick.org/Usage/thumbnails/#creation

You can use -resize rather than -thumbnail

Re: Resizing image to a dimension

Posted: 2014-08-28T12:17:09-07:00
by osnsubra
Thanks for the response.
I have uploaded the original image with dimension 750x1050 in the following location -
https://www.dropbox.com/s/anjp9o6qbqeoi ... n.png?dl=0

The desired dimension 180x340, converted using Photoshop is uploaded here -
https://www.dropbox.com/s/0x0ncyjtkzsnt ... 0.png?dl=0

The dimension 180x340, converted using Imagemagick with command 'convert -resize 180x340!' uploaded here
https://www.dropbox.com/s/uheezikwl3fi3 ... 0.png?dl=0

The imagemagick converted image is stretched as its ignored the aspect ratio. I am looking for the right command that converts to desired format 180x340 with no distortion to the image. Thanks for your help

Re: Resizing image to a dimension

Posted: 2014-08-28T13:13:02-07:00
by fmw42
Your original image has an aspect ratio of 750/1050=0.714285714285714. You want an image with aspect ratio of 180/340=0.529411764705882. These are two very different aspect ratios. There is no way to do that without distorting, padding or cropping. The best I can suggest is

Code: Select all

convert OriginalDimension.png -resize 180x340 -gravity center -background none -extent 180x340 im_padded.png
or

Code: Select all

convert OriginalDimension.png -resize 180x340^ -gravity center -background none -extent 180x340 im_cropped.png
The latter seems to match the PS result, but may not be what you want in all cases, since it may crop parts of the object and not just background as it does in this case.

Re: Resizing image to a dimension

Posted: 2014-08-29T09:45:06-07:00
by osnsubra
Thanks for the response.
On the 2nd command, is there a way it can be zoomed in, so that the size of the bottle can be little bigger. Below are the image links

The im_cropped.png
https://www.dropbox.com/s/5moln3h236max ... d.png?dl=0

PS converted image
https://www.dropbox.com/s/0x0ncyjtkzsnt ... 0.png?dl=0

Re: Resizing image to a dimension

Posted: 2014-08-29T10:00:33-07:00
by fmw42
Try

Code: Select all

convert OriginalDimension.png -resize 180x340^ -resize X% -gravity center -background none -extent 180x340 im_cropped.png
where X is slightly larger than 100 as appropriate for the desired zoom.

Or just multiply 180 and 340 by X as a fraction (slightly larger than 1) and use those as

Code: Select all

convert OriginalDimension.png -resize WxH^ -gravity center -background none -extent 180x340 im_cropped.png
where W=180*X and H=340*X