Page 1 of 1

Centered on a black background

Posted: 2007-08-22T19:50:16-07:00
by strantheman
I did some extensive searching of these forums, but did not find anyone having trouble with -gravity centering as I am. Seems like a relatively simple and common task, and so I'm stumped as to why it is not working for me. I found a good resource that explains exactly how to do it, but it isn't working.

http://www.imagemagick.org/Usage/thumbnails/#pad

I'm using the command to resize an image to 50px wide, and then to center it on a black 75x75 background. Following the example from the above resource, this is my command:

Code: Select all

convert -size 200x200 tall.jpg -resize 50 -background black -gravity center -extent 75x75 tall_pad.jpg
What I end up with is a 75x75 image, but the original image is not centered, it is left justified.

Any help would be greatly appreciated. I really want to understand this very powerful tool.

nic

Re: Centered on a black background

Posted: 2007-08-23T10:21:12-07:00
by Bonzo
Try this:

Code: Select all

convert -size 75x75 xc:black -size 200x200 tall.jpg -resize 50 -gravity center -composite tall_pad.jpg
-size 75x75 xc:black = Create the black background
-size 200x200 tall.jpg -resize 50 = Resize the image
-gravity center -composite = Put the second image ontop of the first

Re: Centered on a black background

Posted: 2007-08-23T14:12:05-07:00
by strantheman
Hi Bonzo! Thanks for your assistance, bro.

Your xc:black command was news to me; hadn't seen that before. Plus, your -composite command was probably what I was missing! I altered the -resize this time to have it constrain within 75x75 (I have some wide thumbs, and some tall) and I got exactly what I wanted! Here is the resulting command:

Code: Select all

convert -size 75x75 xc:black tall.jpg -resize 75x75 -gravity center -composite tall_pad.jpg
It works for both my tall graphics, centering them horizontally, and for my wide ones, centering them vertically.

Your help is much appreciated. My client indirectly thanks you!

p.s. I removed the -size 200x200 part, i've never been quite sure what that was supposed to do.

nic

Re: Centered on a black background

Posted: 2007-08-24T01:08:27-07:00
by Bonzo
I am glad you got what you wanted nic.

The -size 200x200 will speed up the resizing of jpgs. I do not know how much it speeds it up and it can be left out.
I use php and put the original size of the image in there using getimagesize( ).

Re: Centered on a black background

Posted: 2007-08-24T14:14:43-07:00
by strantheman
Cool, thanks for the tip. Faster is faster; I do have that data in my database as well, so I might as well use it. :)

ill be around, see ya

nic

Re: Centered on a black background

Posted: 2007-08-24T22:38:17-07:00
by anthony
More than likely the reason the first 'primary' IM examples solution failed is you have an old version of IM examples.
Bonzo's solution is equivalent to the fourth method given. Overlaying the thumbnail on an existing image. In this case the -size 200x200 xc:black.

In short I suggest you read the IM Examples, on Canvas creation which covers this type of thing.

I also suggest you look at 'Cutting and Bordering'...