Merge three images at different positions on a transparent canvas

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
276QeqxYSCrFENSx
Posts: 3
Joined: 2015-09-21T08:25:56-07:00
Authentication code: 1151

Merge three images at different positions on a transparent canvas

Post by 276QeqxYSCrFENSx »

I have three PNGs that I want merged at different positions on a transparent canvas with a fixed size.

Let's say the canvas is 200x200, the images all about 50x50 and I want the first at 25x 125y, the second at 75x 125y and the third at 125x 125y. How would I go about this?

Example:

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Merge three images at different positions on a transparent canvas

Post by snibgo »

You might use "-layers" with a page setting, or "-composite" with a geometry.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Merge three images at different positions on a transparent canvas

Post by fmw42 »

276QeqxYSCrFENSx
Posts: 3
Joined: 2015-09-21T08:25:56-07:00
Authentication code: 1151

Re: Merge three images at different positions on a transparent canvas

Post by 276QeqxYSCrFENSx »

snibgo wrote:You might use "-layers" with a page setting, or "-composite" with a geometry.
I couldn't get the canvas to be transparent. It always turns out black.

Code: Select all

convert --size200x200 xc:none output.png -composite 1.png -composite 2.png -composite 3.png
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Merge three images at different positions on a transparent canvas

Post by 246246 »

276QeqxYSCrFENSx wrote: I couldn't get the canvas to be transparent. It always turns out black.
You will need -background none. And output file should be placed last of the command sequence.

Code: Select all

convert xc:none[200x200\!] -background none \( rose: -resize 50x50\! -geometry +25+125 \) -compose over -composite \( rose: -resize 50x50\! -geometry +75+125 \) -compose over -composite \( rose: -resize 50x50\! -geometry +125+125 \) -compose over -composite show:
or

Code: Select all

convert xc:none[200x200\!] -background none \( rose: -resize 50x50\! -repage +25+125 \) \( rose: -resize 50x50\! -repage +75+125 \) \( rose: -resize 50x50\! -repage +125+125 \) -layers merge show:
276QeqxYSCrFENSx
Posts: 3
Joined: 2015-09-21T08:25:56-07:00
Authentication code: 1151

Re: Merge three images at different positions on a transparent canvas

Post by 276QeqxYSCrFENSx »

Thanks 246246, the first command is what I was looking for. It works with "gravity" and solves the problem.
Post Reply