5

I have a image and i put watermark there, but i want that watermark hs a opacity like 30%.

My code:

    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;

How can i say that logo has opacity like 30%?

2 Answers2

0

Your need to change the opacity of "logo.png" use blur, then compose it like code snipp above.

Ngoc Bui
  • 56
  • 1
-3

Sharp cant do this yet.

Alternative method is use canvas to change image opacity before composite. https://github.com/Automattic/node-canvas/blob/master/examples/globalAlpha.js