【问题标题】:How to mask an image with another b/w image in NodeJS?如何在 NodeJS 中用另一个黑白图像屏蔽图像?
【发布时间】:2022-09-29 22:05:59
【问题描述】:

所以我想屏蔽这张图片

有了这张图片

这将导致此图像

如何在 NodeJS 中做到这一点?

    标签: node.js image-manipulation jimp


    【解决方案1】:

    这很容易。我们只需要使用JIMPNodeJS 的包。 我们也可以将图像输出为文件或缓冲区以在画布中使用。

    var Jimp = require('jimp');
    Jimp.read(image_1,(err, image) => {
      Jimp.read(image_2,(err1,image1) => {
        image1.resize(image.bitmap.width,image.bitmap.height)
        image.mask(image1,0,0)
        image.write(output_image) //for a file output
    
    //for buffer output
        image.getBufferAsync('image/png'); //for transparent image use image/png
      })
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      相关资源
      最近更新 更多