如何在nodejs中给图片添加水印。我正在使用环回框架,我想为上传的每个图像添加水印,我尝试了几个图像处理模块,但无法实现水印。
我用代码尝试了图像水印库:
watermark.embedWatermark('./server/storage/images/img_hkd.jpg', { 'text': 'sample watermark' });
但我收到此错误:错误:生成识别 ENOENT
最佳答案
使用jimp
模块代替watermark
。它对我有用。
let imgActive = 'active/image.jpg';
Jimp.read('raw/originalimage.png')
.then((tpl) => tpl.clone().write(imgActive))
.then(() => Jimp.read(imgActive))
.then((tpl) =>
Jimp.read('raw/logo.png').then((logoTpl) => {
logoTpl.opacity(0.2)
return tpl.composite(logoTpl, 512, 512, [Jimp.BLEND_DESTINATION_OVER])
}),
)
.then((tpl) => tpl.write('raw/watermark.png'))
}
关于javascript - Nodejs如何给图片添加水印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42158636/