Page 1 of 1

Convert: centering a "best fit" resized image

Posted: 2011-09-26T17:14:02-07:00
by JoshP
I'm trying to resize a picture and put it on top of a black background using this command
Let's say somePic.jpg does not fit the ratio of 300x100, I would expect it to be centered within the slot allocated to it, but with the this command its left aligned.

Code: Select all

convert -size 300x250 -quality 80.0 xc:black \( -gravity Center 'somePic.jpg' -resize 300x100 -repage 0x0+0+110 \) -flatten 'newPic.jpg'
I've had luck doing this with this style command:

Code: Select all

convert "somePic.jpg" -resize 144x82 -size 144x82 xc:#343434 +swap -gravity center -composite "newPic.jpg"
Thanks

Re: Convert: centering a "best fit" resized image

Posted: 2011-09-26T17:48:34-07:00
by fmw42
try

convert somePic.jpg -resize 144x82 -background black -gravity center -extent 144x82 newpic.jpg

see
http://www.imagemagick.org/Usage/crop/#extent

Re: Convert: centering a "best fit" resized image

Posted: 2011-09-26T22:06:09-07:00
by anthony
There are two composition positioning methods in IM
  • geometry offsets with gravity placement typically two images only
  • layering of multiple images with canvas size, and page offsets (relative to a origin)
which method is used by what composition operator depends on that operator. Only one operator understands both and that is -layer composite, which uses geometry/gravity one for global placement, and layer/page for individual placement relative to global placement.

See IM examples, Compositing Images, Positioning The Overlay Image
http://www.imagemagick.org/Usage/compose/#geometry

The section immediatally above lists the composition operators and what positioning methods they use (if any)