use*_*266 1 javascript node.js express loopbackjs
如何在 nodejs 中为图像添加水印。我正在使用环回框架,我想为上传的每个图像添加水印,我尝试了几个图像处理模块,但无法实现水印。
我用代码尝试了图像水印库:
watermark.embedWatermark('./server/storage/images/img_hkd.jpg', { 'text': 'sample watermark' });
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:错误:生成识别 ENOENT
小智 6
而不是watermark使用jimp模块。它对我有用。
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'))
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7606 次 |
| 最近记录: |