gifsicle
gifsicle copied to clipboard
Option to composite an overlay on frames of GIF?
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:
Example frame:
Example overlay:
Example composited overlay on frame:
Example of "finished" captioned animation:
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
@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?
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.
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 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