javascript - Nodejs如何给图片添加水印

标签 javascript node.js express loopbackjs

如何在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/

相关文章:

javascript - 如何在即时消息应用程序中为不同的用户分配不同颜色的对话泡泡

node.js - API触发消息的头像如何设置?

node.js - jade能在不刷新页面的情况下显示新的值吗?

javascript - 如何加快倒计时?

javascript - Ember : transition to route passing the ID instead of obj

javascript - Microsoft Bot 框架,从 Javascript 设置用户状态

javascript - 基于 Redux 状态返回值的货币实用函数?

javascript - 如何检查 NodeJS 中的 JSON 是否为空?

javascript - 刷新 Express NodeJS API 的内容

node.js - 这个NodeJS集群master会崩溃吗?