These are my codes I used for adding watermark to an image:
const ORIGINAL_IMAGE = "https://example/sample_image;
const LOGO = fs.readFileSync('gangle.png');
const LOGO_MARGIN_PERCENTAGE = 5;
let [image, logo] = await Promise.all([
Jimp.read(ORIGINAL_IMAGE),
Jimp.read(LOGO)
]);
logo.resize(image.bitmap.width, Jimp.AUTO);
const xMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100;
const yMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100;
const X = image.bitmap.width - logo.bitmap.width - xMargin;
const Y = image.bitmap.height - logo.bitmap.height - yMargin;
image.composite(logo, X, Y, [
{
mode: Jimp.BLEND_SCREEN,
opacitySource: 0.1,
opacityDest: 1
}
]);
image.write('animatedimg.gif')
But it only works on image with filetype png/jpg/jpeg. It doesn't work on gif image.
It will generate a file 'animatedimg.gif', but that file won't load to any image viewer or browser.
If I try to open that file in mac, the popup will appear with message: "The file “animatedimg.gif” could not be opened because it is empty."
Is there any way to do that in jimp? Or is there other npm package for that? Thank you.