I want to merge 2 images using node.js. Or rather, i want to place one smaller image on cordinates x,y on a larger image. Even more precise: I have an image of glasses, and an image of a face and i want to put the glasses on the face. I did some googling, and found some image manipulating libraries, but none seem to be able to merge images.
Node. js has an ecosystem of libraries you can use to process images, such as sharp, jimp, and gm module.
You might need this: https://github.com/zhangyuanwei/node-images
Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Nodejs
images("big.jpg").draw(images("small.jpg"), 10, 10).save("output.jpg");
I do no have enough reputation to add a comment, or else I would to Schmidko's answer.
Sharp works well, however, overlayWith is deprecated and you instead need to use composite. See below:
sharp(path + 'example.jpg')
.composite([{input: path + 'logo.png', gravity: 'southeast' }])
.toFile(path + 'output.png');
If you would like to center the image being overlayed:
gravity: 'centre'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With