So I want to mask this image
with this image
which will result in this image
How to do this in NodeJS?
This can be pretty easy. We just need to use the JIMP package for NodeJS. We can output the image as a file or a buffer to use in canvas too.
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
})
})