How to apply an overlay on each frame of a Gif
Question about an existing feature
How to apply an overlay on each frame of a gif?
What are you trying to achieve?
I'm trying to add a watermark to a gif. The issue is that the overlay/watermark is applied only on the first frame of the gif.
When using the option: tile: true the watermark is repeated multiple times in each frame, as shown here:

When I remove tile: true from the options, the overlay gets applied only to the first frame:

I want to apply the overlay to each frame of the gif (on the bottom right, as shown in the image below, I've added a slack watermark for illustration purposes).
When you searched for similar issues, what did you find that might be related?
I viewed all the open issues, and most of them point to using tile: true, which only repeats the overlay infinitely on each screen.
Example issues: https://github.com/lovell/sharp/issues/3122, https://github.com/lovell/sharp/issues/2680, https://github.com/lovell/sharp/issues/3121
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
const gifFile = fs.readFileSync(GIF_PATH);
const response = await fetch(WATERMARK_URL);
const watermarkBuffer = Buffer.from(await response.arrayBuffer());
const watermark = await sharp(watermarkBuffer)
.resize(WATERMARK_WIDTH, WATERMARK_HEIGHT)
.toBuffer();
const watermarkCompositeOptions = [
{
input: watermark,
top: watermarkTopPosition,
left: watermarkLeftPosition,
tile: true,
},
];
const gifWithWatermark = await sharp(gifFile, { animated: true })
.composite(watermarkCompositeOptions)
.gif()
.toBuffer();
fs
.createWriteStream(`/tmp/gif-${generateRandomId()}.gif`)
.write(gifWithWatermark);
Hi, you'll need to expand the dimensions of the tiled watermark overlay to match those of each page/frame.
Hi, you'll need to expand the dimensions of the tiled
watermarkoverlay to match those of each page/frame.
@lovell thanks for the reply ✋ So, in order for it to work, if the frame/gif is 600x600, the watermark has to be 600x60?
Closing this issue since making the size of the watermark the same size as the gif worked (making the background transparent and placing the watermark at the bottom right).
This detail about overlayed images needing to be the same size as the base gif really should be in the docs somewhere. As far as I can tell this issue is the only place on the internet where this is mentioned.