Dynamic Watermark is npm watermark module to add logo watermark to an image. It can add an image as well as text watermark on given positions. This node module has features like we can provide the type of watermark for eg: image or text watermark, logo position in pixels etc. This tutorial will help you to add watermark in nodejs to image.
In this tutorial, we are going to create an example in nodejs and we are using dynamic-watermark module to add watermark to the image. At the end of the tutorial, you will have a clear understanding of the example to add watermark in nodejs.
Let’s get started by creating nodejs application.
create sample application.
It will create package.json file for us and it will look like this.
Dynamic watermark package installation:
Install other dependencies for our nodejs app.
Create index.js file inside our project directory.
After creating nodejs server our index.js file will look like this.
- Put image file (jpg/png) in the same directory as our source file on which we are going to add watermark. In my case, I am using source.jpg image.
- Put logo file (jpg/png) in the same directory as our logo file, which we are going to add as a watermark. In my case, I am using logo.png image.
Finally, our folder structure will look like this:
We are done! Now its time to run our application.
In this example we are having only server-side logic and we haven’t use any frontend. To test our code just open the browser and hit URL http://localhost:8080/add-watermark. You will get true in response if it will add watermark. Go to our project folder and you will see that output.jpg file is generated will watermark added to it. If you want to add Frontend then go for either react or angular and make HTTP call.
If you want to add this package to an existing project then follow these steps:
- include dynamic-watermark package:
- Provide following options:
- The final step is to call embed method by passing above options.
If you are facing any issue then dont forget to open issue on GitHub. Open issues here