Search code examples
node.jsgifanimated-gif

How to add text to a gif node.js


I am dealing with a problem. I want to download a gif and place text at the top for example add the text "Top text" on this gif.

I have looked through google codegrepper and stackoverflow for an answer but nothing

How would i accomplish that? Documentation would be appreciated.


Solution

  • You can use tenorjs to fetch the GIFs. If you only want to use one certain GIF, you download that, and add that to your Files.

    You can use something like text-on-gif to display text on the GIF.

    Basic Usage of text-on-gif:

    const textOnGif = require("text-on-gif");
    
    (async function(){
    
        //get gif as buffer
        var gifBuffer = await textOnGif({
                file_path:"/path/file.gif", //path to local file or url
                textMessage:"custom message"
            });
        console.log(gifBuffer)
    
        //write gif as file
        await textOnGif({
            file_path:"/path/file.gif", //path to local file or url
            textMessage:"custom message",
            write_as_file:true,
            getAsBuffer:false,
            write_path:"path/gif-with-text.gif"
        });
    
    })();