Use Node. js to add watermarks to images.

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.