text-on-gif is a simple package for writing text on gifs
NOTES This is a fork of https://github.com/sanidhya711/text-on-gif
const { TextOnGif } = require('gift-on-text')
const gifURL = 'https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif';
// -- In async function or top-level await supported namespace --
const gif = new TextOnGif(gifURL);
await gif.setText('Hello', {
alignmentY: "top",
alignmentX: "left"
});
// Update on the fly
gif.on("frameIndexUpdate", async (frameIndex) => {
if (frameIndex == 15) {
gif.canvasOptions.y = 150;
gif.canvasOptions.x = 110;
await gif.setText("World");
}
});
await gif.toFile('result.gif'); // Save new gif
const gifBuffer = await gif.toBuffer(); // get buffer
Create a new TextOnGif
instance, then call and await .setText()
const gif = await new TextOnGif(gifURL)
.setText(text, options)
Type | Default Value |
---|---|
string | ' ' |
Parameter Name | Type | Default Value |
---|---|---|
fontSize | String | "32px" |
fontStyle | String | "calibri" |
fontColor | String | "white" |
strokeColor | String | "transparent" |
strokeWidth | Number | 1 |
alignmentX | String | "middle" |
alignmentY | String | "bottom" |
positionX | Number | null |
positionY | Number | null |
offsetX | Number | 10 |
offsetY | Number | 10 |
rowGap | Number | 5 |
repeat | Number | 0 |
Boolean | false | |
transparent | Boolean | false |
To use a font file that is not installed as a system font, use registerFont(). This must be done before calling textOnGif()
call gif.toFile(path)
to save as a file.
await gif.toFile('output/myGif.gif')
const buffer = await gif.toBuffer();
-
"extractionComplete"
type:
() => void
-
"frameIndexUpdate"
type:
(index:number) => void
-
"progress"
type:
(percent:number) => void
-
"finished"
type:
() => void
All the parameter details are listed below
-
Pull requests to improve this ugly readme are more than welcome :D
-
Or if you have any suggestions or request for new features feel free to open an issue.
Text to be printed on the gif
Can be a String, Number or Boolean.
This option is currently non-functional.
if set to true, when you call the textOnGif function to write on the gif, the text will be retained on the source and all consecutive textOnGif function calls will return the gif with the cumulative text.
useful when you have to write text on multiple places on the same gif
Gif on which the text is to be printed,
path to a local gif file / URL or in-memory buffer
gif.filePath is read only and cant be altered after the TextOnGif object is created
Size of font, any CSS font-size value
Invalid values might break fontStyle and fontColor too and result inna very ugly output
Any installed font. Example: (fontStyle: "Comic Sans MS")
Invalid values might break fontSize and fontColor too and result inna very ugly output
Color of the font. Accepts any CSS Color.
Invalid values might break fontSize and fontStyle too and result inna very ugly output
Color of the stroke, leave as "transparent" for no stroke.
Accepts any CSS Color.
Number specifying the line width(Outline) of drawn text,
in 'coordinate space units'
- "left"
- "center"
- "right"
- "top"
- "middle"
- "bottom"
Starting position of text on the x axis(in pixels)
must be a Number
Starting position of text on the y axis(in pixels)
must be a Number
Offset of starting position of text from left or right(in pixels) depending on alignmentX, must be a Number
not taken into account if positionX is specified
Offset of starting position of text from Top or Bottom(in pixels) depending on alignmentY, must be a Number
not taken into account if positionY is specified
Vertical gap between rows of text(in pixels)
taken into account when text to be printed is too long for one row and is wrapped to the next row
Number of times to repeat the GIF, n Number
- If n is -1, play once.
- If n is 0, loop indefinitely.
- If n is a positive number, loop n times.
whether the gif should have a transparent background or not
- If set to true then all black pixels are rendered as transparent
- If set to false then transparent pixels are automatically rendered as black
Thanks goes to these wonderful people (emoji key):
ienadlard 💻 |
Cryptizism 📖 |
Ian Wijma 🐛 |
Asrın Tekelioğlu 🐛 |
This project follows the all-contributors specification. Contributions of any kind welcome!