Okay... lets take this back to first principles. Though it is rather like the examples for 'simple border overlays'
http://www.imagemagick.org/Usage/thumbn ... er_overlay
From "imageshack" I downloaded "illustration.jpg" (the main image) and "card.gif" (the surrounding 'border' image) that you want to insert the illustration into.
First forget the mask, it is not important. The "card.gif" image itself already has a 'hole' in it which can be used to mask the illustration image directly.
However as you are using a GIF image, which only allows boolean transparency, the hole will have a highly 'aliased' (stair-cased') edge to it. That is not very good, and I recommend you convert "card.gif" into PNG format, flatten it on black, and re-cut the hole either using a GUI image editor (such as GIMP or photoshop) or using the mask you previous supplied.
This re-masking of the "card" image is only needed once, and saved as PNG (not GIF), even though your final image may be GIF.
Second you want the resulting image to be the size of the "card.gif" so that makes it the "background" image.
Third You will thus want to place the illustration UNDER that card so that means you need to use
a
DstOver composition method. See IM Examples
Duff-Porter Compose Methods and more specifically
Dst Over, or compose 'under' destination
So lets do this with a
Center gravity, and then adjust the geometry offset until the illustration is correctly centered in the card hole. As the images are gravity centred this offset will remain the same regardless of the size of the illustration. You can resize, scale, pad or distort the illustration as you like and it will still position correctly with the same offset.
Code: Select all
convert card.gif illustration.jpg -geometry +0-17 \
-gravity center -compose DstOver -composite result.png
ASIDE: the card hole is not very symmetrical!
Now normally the illustration should completely 'fill' the hole in the "background" card image, but in this case the illustration does not even touch the edges of the hole!!!!
Fill with black...
Code: Select all
convert card.gif illustration.jpg -geometry +0-17 \
-gravity center -compose DstOver -composite \
-compose Over -background black -flatten result.png
Resize illustration a bit larger
Code: Select all
convert card.gif \( illustration.jpg -resize x300 \) -geometry +0-17 \
-matte -gravity center -compose DstOver -composite \
-compose Over -background black -flatten result.png
You can finish the task by making the corners of the card transparent using...
http://www.imagemagick.org/Usage/thumbnails/#rounded
There that is the full solution!