Use Node. js to add watermarks to images.
I. preparations:
First, make sure that you have installed the node environment locally.
Then, we need to use a Node. js Library: images for image editing.
The address of this library is https://github.com/zhangyuanwei/node-images. the author defines "Node. js lightweight cross-platform image codec library" and provides a series of interfaces.
First, we need to install the images Library:
Npm install images
Ii. Go directly to the DEMO:
The procedure is as follows:
Step 1: folder structure
Step 2: JS Code
Var images = require ('images'); var path = require ('path'); var watermarkImg = images('water_logo.png '); var sourceImg = images('source.png '); // For example, in the lower-right corner, obtain the source image size and watermark image size. var sWidth = sourceImg. width (); var sHeight = sourceImg. height (); var wmWidth = watermarkImg. width (); var wmHeight = watermarkImg. height (); images (sourceImg) // you can specify the position of the drawn coordinate. The distance from the bottom right corner is 40px. draw (watermarkImg, sWidth-wmWidth-40, sHeight-wmHeight-40) // The save format automatically identifies .save('saveimg.png ');
Step 3: run the node app command
Step 4: after running the node command, the folder structure is shown in figure
Step 5: The final watermark image
The above section describes how to use Node. js watermarks images. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!