Page 1 of 1

Different Canvas sizes

Posted: 2011-09-05T11:39:18-07:00
by normaldenker
Hello,

I was searching a lot but did not find a solution for the following problem:

My original jpeg has a size of, e.g., 1024/768.

I want to resize and crop to different sizes. In three steps I was trying to transform it to 80px/50px - 480/280 - 150/150.

For resizing I already tried several commands, this for example:
resize 480x280 -gravity Center -crop 480x280+0+0

or

resize 480x280 -gravity Center -crop 480x280+0+0 +repage

The problem is: Using the "+repage"-command nothing happens ...

I don't want to have a white border. The picture should be resized in the best way possible.

Hope you understand what I mean.

Thanks for your answers.

Re: Different Canvas sizes

Posted: 2011-09-05T12:26:24-07:00
by fmw42
+repage only affects the virtual canvas and does nothing if your output is jpg.

-resize 480x280 will preserve the aspect ratio of your input image. So if you aspect ratio of your input does not match that of your resize dimensions then it will choose to match one dimension and have the other smaller than specified. So to get the image to be the size you want you would need to pad with some color using -background somecolor -gravity center -extent 480x280, e.g.

convert yourimage -resize 480x280 -background white -gravity center -extent 480x280 resultimage

However the other choice if the two do not have the same aspect ratio is to crop. That is done by using the ^ in the resize, so that it resizes to the smaller size and leaves the other dimenion bigger than desired.

convert yourimage -resize "480x280^" -background white -gravity center -crop 480x280+0+0 +repage resultimage

The +repage is needed for example for png or gif output, but not for jpg, so that the virtual canvas is made the same size as the cropped image and not left as the size after the resize.

The other choice is to tell the resize that you want the exact size specified, but then you must be willing to accept distortion as it stretches on or the other dimension.

convert yourimage -resize "480x280!" resultimage

see
http://www.imagemagick.org/script/comma ... p#geometry

You did not say what version of IM you are using and what platform. Some of these options are not available on very old systems. For windows users also see syntax differences at http://www.imagemagick.org/Usage/windows/

Re: Different Canvas sizes

Posted: 2011-09-07T04:56:05-07:00
by anthony
See the thumbnail resize and pad methods in...
http://www.imagemagick.org/Usage/thumbnails/#fit
and specifically the summery at
http://www.imagemagick.org/Usage/thumbn ... it_summery

If you don't care about the aspect ratio at all, but want to stretch/compress the width and height un-equally use a '!' flag with the resize
http://www.imagemagick.org/Usage/resize/#noaspect

Both sections of IM examples, thumbnails and resize, are a good read if you really want to control exactly what you are wanting to get.