【问题标题】:Watermark with sharp带有锐利的水印
【发布时间】:2019-12-01 21:42:34
【问题描述】:

我有一张图片,我把水印放在那里,但我希望水印的不透明度为 30%。

我的代码:

    let sharp = require('sharp');
    let buffer = null;

    await sharp(image)
        .composite([{ input: './logo.png', gravity: 'center' }])
        .sharpen()
        .withMetadata()
        .toBuffer()
        .then(function(outputBuffer) {
            buffer = outputBuffer;
        });
    return buffer;

我怎么能说徽标的不透明度为 30%?

【问题讨论】:

  • 我相信你需要合成另一个只有 0.7 alpha 通道的图像,并使用混合模式“dest-in”
  • @Asthmatic 对不起,我不明白。你能传递一个示例代码吗?
  • 类似于github.com/lovell/sharp/issues/405#issuecomment-208033263,但将混合模式设置为dest-in...但在您的情况下,您不需要reducer,因为它只是2个图像
  • @Asthmatic 我这样做了,所有图像都是黑色的,水印是不透明度的 0%

标签: node.js sharp


【解决方案1】:

您需要更改“logo.png”的不透明度使用blur,然后像上面的代码片段一样编写它。

【讨论】:

    【解决方案2】:

    夏普还不能做到这一点。

    另一种方法是在合成之前使用画布更改图像不透明度。 https://github.com/Automattic/node-canvas/blob/master/examples/globalAlpha.js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 2015-08-06
      • 1970-01-01
      相关资源
      最近更新 更多