- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to flip an image in Node Jimp?
NodeJS – Flip() is an inbuilt function that is used to flip the images. The images can be flipped either vertically or hoizontally as defined in the function. By default, the images are flipped horizontally.
Syntax
flip(h, v, cb)
Definition of flip() paramters
h – It takes a boolean value as an input. Image will be flipped horizontally if this is TRUE.
v – It takes a boolean value as an input. Image will be flipped vertically if this is TRUE.
cb – This is also an optional parameter that can be invoked after the compilation is complete.
Input Image
Using Node JIMP – FLIP()
Before proceeding to use flip() 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 flip.js file and copy-paste the following code snippet in it.
Use node flip.js to run the code.
Note − Note that 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 flip() { // Function name is same as of file name // Reading Image const image = await Jimp.read ('/home/jimp/tutorials_point_img.jpg'); image.flip(true, false, function(err){ if (err) throw err; }) .write('/home/jimp/flip.jpg'); } flip(); // Calling the function here using async console.log("Image is processed successfully");
Output
Using Node JIMP – FLIP() when 'v' is TRUE
Example
const Jimp = require('jimp') ; async function flip() { // Reading Image const image = await Jimp.read ('/home/jimp/tutorials_point_img.jpg'); image.flip(true, true, function(err){ if (err) throw err; }) .write('/home/jimp/flip.jpg'); } flip(); console.log("Image is processed successfully");