Merge animated GIF and PNG with transparency

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?".
Locked
DieterK
Posts: 4
Joined: 2017-04-19T01:07:55-07:00
Authentication code: 1151

Merge animated GIF and PNG with transparency

Post by DieterK »

Hello,

I have an animated GIF (fire.gif) and I would now like to use ImageMagick to insert a PNG with transparency (product.png) in the middle of this GIF.

Example:
Animated GIF: fire.gif 600x600
PNG file with transparency: product.png 400x400

The PNG should be placed in the middle of the GIF (top layer) and slightly smaller (300x300)

I already tried it with convert (composite) and composite, unfortunately without success. In most attempts the GIF was not animated properly or did not work at all.

I would be very happy about tips and hints.

Thanks,
Dieter

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

Re: Merge animated GIF and PNG with transparency

Post by snibgo »

What version of IM? On what platform? Please supply sample input files.

You want to composite a png over every frame of a gif. There are three stages:

1. Create frame images from the input gif: "-layers coalesce".

2. Compose the png over each of those frame images: "-layers composite".

3. Write the output gif.
snibgo's IM pages: im.snibgo.com

DieterK
Posts: 4
Joined: 2017-04-19T01:07:55-07:00
Authentication code: 1151

Re: Merge animated GIF and PNG with transparency

Post by DieterK »

Thanks,

so I have to split the GIF first into individual files, then edit the individual images and then create a new gif from them?

Or can I do that in one command?

Thanks

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

Re: Merge animated GIF and PNG with transparency

Post by snibgo »

You have to create individual images that represent each entire frame, but you don't need to save these as files.

The command could be something like (IM v7, Windows BAT syntax):

Code: Select all

magick ^
  in.gif ^
  -layers coalesce ^
  null: ^
  in.png ^
  -gravity Center -layers composite ^
  out.gif
snibgo's IM pages: im.snibgo.com

Locked