gifsicle icon indicating copy to clipboard operation
gifsicle copied to clipboard

Option to composite an overlay on frames of GIF?

Open gingerbeardman opened this issue 8 years ago • 5 comments

Sometimes I have the need to "badge" a GIF with a caption, username, url, or some other text.

The way I do it is to prepare a transparent image with the text on it, which can then be combined or overlaid on each frame of the GIF.

My current solution is quite cumbersome, and relies on ImageMagick's composite command:

gifsicle -E anim.gif
for f in *.gif.*; do composite overlay.gif $f $f; done
gifsicle --loopcount *.gif.* > captioned.gif
rm *.gif.*

This explodes the GIF, composites the overlay onto each frame in a loop, reassembles the GIF, and finally deletes the exploded frames.

But of course this solution is somewhat limited and not very flexible.

Do you have any thoughts on this? Would you consider adding such a feature?

Example animation: anim

Example frame: frame

Example overlay: overlay

Example composited overlay on frame: composited

Example of "finished" captioned animation: captioned

gingerbeardman avatar Jun 16 '16 14:06 gingerbeardman

I tried this and "composite" didn't work... seems there may've been an update since this post. Altho, I did find this line that would fix it: from URL: http://www.lcdf.org/gifsicle/man.html

To overlay one GIF atop another—producing a one-frame output GIF that looks like the superposition of the two inputs—use gifsicle twice:

gifsicle bottom.gif top.gif | gifsicle -U "#1" > result.gif

ripscreates avatar Jul 16 '17 12:07 ripscreates

@ripleytech the composite command is part of imagemagick not gifsicle, I should have mentioned that!

I'll try the "twice" method you mention, but it sounds like it only works for single frames?

gingerbeardman avatar Jul 17 '17 10:07 gingerbeardman

ah right! i did run into that error about composite. yes, that twice method is for single frames. i imagine, for a completed GIF, one would have to explode the frames, overlay them into new files, then group those new files into a GIF.

Since I was making my project from new stills, I added the overlay before creating into a GIF.

ripscreates avatar Jul 18 '17 07:07 ripscreates

Please, consider adding an option to place a watermark over animation. E.g. I capture a command line output (bright lines inside the dark area) and would like to put a small semi-transparent play button later in one of the corners to indicate that it is animated.

sergeevabc avatar Jun 14 '21 17:06 sergeevabc

@sergeevabc you can do this with imagemagick right now:

  • see above!

A more complete script of this method (uses gifsicle and imagemagick):

#!/bin/bash
source=$1
caption=$2
: ${1?"Usage: $0 anim.gif overlay.gif [output.gif]"}
: ${2?"Usage: $0 anim.gif overlay.gif [output.gif]"}

fnsource=$(basename "$source" .gif)
fncaption=$(basename "$caption" .gif)

output=${3:-"$fnsource-$fncaption.gif"}

gifsicle -E $source
for f in *.gif.*; do composite $caption $f $f; done
gifsicle --loopcount *.gif.* > $output
rm *.gif.*

how to run the command ./caption.sh anim.gif overlay.gif [output.gif]

note: if you do not specify an output name, it will be named using original filenames, eg. anim-overlay.gif

gingerbeardman avatar Jun 14 '21 19:06 gingerbeardman