The following approach covers how to convert PNG to JPG in Node.js using Jimp module. Jimp is an image processing library that we can use to do a lot of operations on images. Jimp stands for JavaScript Image Manipulation Program.
Approach: We will use the following steps:
- Import Jimp module in our application.
- Read PNG image in Jimp module.
- Convert PNG to JPG using Jimp functionalities.
- Return the final JPG Image.
Setting up environment and Execution:
Step 1: Initialize node.js project with the following command.
npm init
Step 2: Install the required module using the following command.
npm install jimp
Step 3: Get one sample PNG file, for this example, we have taken the below image and placed it in the static folder.

Project Structure: It should look like the following:

Step 4: Create an index.js file with the following code.
index.js
const Jimp = require( "jimp" );
Jimp.read( "./static/GFG_IMG.png" , function (err, image) {
if (err) {
console.log(err);
return ;
}
image.write( "./output/out.jpg" );
});
|
Step 5: Run node.js project using the following command.
node index.js
Output: See the JPG output in the output folder.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Apr, 2021
Like Article
Save Article