tags:

views:

8

answers:

2

I'm looking for a way that I can take say, a 200x200 pixel image and center it over a background that's 500x500 pixels. The background should be the color of the top-left corner of the 200x200 pixel image.

I get the -gravity and -fill flags, but I'm having trouble finding a way to grab that top-left corners color to pass to the -fill flag.

A: 

hmm I thought I did this with Image Magick but it turns out I used PIL. If you're using Python you can use PIL to get that corner pixel color like so:

import Image

img = Image.open(filename)

if img.mode != "RGB":
    img = img.convert("RGB") 

left_corner = img.getpixel((0,0))
Khorkrak
A: 

I haven't found an easier way, so I'm cropping the corner, resizing it which results in a solid color image, then compositing them. Made possible by the use of STDIN and STDOUT file descriptors. The "png:-" bits tell imagemagick to pass the image data in PNG format from what I understand.

convert -crop 1x1+0+0 image.png png:- | convert -resize 500x500 - png:- | convert -gravity center -composite - image.png new_image.png
joebert