How to convert PNG to JPG using Node.js ?
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.
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.
Step 5: Run node.js project using the following command.
Output: See the JPG output in the output folder.