How to apply a Sepia tone to an image in Node Jimp?


NodeJS – Sepia() is an inbuilt function that is used to apply a sepia or wash tone to the image.

Syntax

sepia(cb)

sepia() paramters

  • cb – This is an optional parameter that can be invoked after the compilation is complete.

Input Image

Using Node JIMP – SEPIA()

Before proceeding to use sepia() functions, please check that the following statements are already executed for setting up the environment.

  • npm init -y // Initialising the Node environment

  • npm install jimp --save // Installing the jimp dependency

  • Create a sepia.js file and copy-paste the following code snippet in it.

  • Use node sepia.js to run the code.

Note: – The method name should match with the JS file name. Only then, it will be able to call the desired method.

Example

const Jimp = require('jimp') ;

async function sepia() {
   // Reading Image
   const image= await Jimp.read
   ('/home/jimp/tutorials_point_img.jpg');
   image.sepia()
   .write('/home/jimp/sepia.jpg')
}

sepia(); // Calling the function here using async
console.log("Image is processed successfully");

Output

Using Node JIMP – Sepia() with 'cb' parameters

Example

const Jimp = require('jimp') ;

async function sepia() {
   // Reading Image
   const image = await Jimp.read
   ('/home/jimp/tutorials_point_img.jpg');
   image.sepia(function(err){
      if (err) throw err;
   })
   .write('/home/jimp/sepia.jpg');
}

sepia();
console.log("Image is processed successfully");

Output

Updated on: 27-Apr-2021

139 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements