Welcome folks today in this blog post we will be using the jimp
library to add the text and image
watermark inside images
in node.js
. All the full source code of the application is shown below.
Get Started
In order to get started you need to make a new node.js
project using the below command as shown below
npm init -y
npm i jimp-watermark
And after that you will be seeing the below directory
structure of the node.js app
Now we need to copy paste the below code to add the text
watermark on top of the profile.png
image file as shown below
index.js
1 2 3 4 5 6 7 8 9 10 11 |
let watermark = require('jimp-watermark') let options = { 'ratio':0.9, 'opacity':0.9, 'dstPath':'./watermark.jpg', 'text':'John Williamson', 'textSize':8 } watermark.addTextWatermark('profile.png',options) |
As you can see we are importing the jimp
package and inside it we are controlling the opacity
and the text
property what text you want to write and then we are controlling the size of the text passing the value from 1 to 8
. And then we are using the addTextWatermark()
method to add the text logo on image passing the input
image and the options.
Now we will be adding the image
or logo watermark to the input image using the addWatermark()
method and passing the options as shown below
index.js
1 2 3 4 5 6 7 8 9 |
let watermark = require('jimp-watermark') let options = { 'ratio':0.9, 'opacity':0.9, 'dstPath':'./watermark.jpg' } watermark.addWatermark('profile.png','logo.png',options) |