flip mirrors the image. A horizontal flip swaps left and right, like a mirror; a vertical flip turns it upside down.
Signature
image.flip(options: { horizontal?: boolean; vertical?: boolean }): thisflip changes the image in place and returns it, so you can chain more calls after it.
Options
| Option | Type | Default | Description |
|---|---|---|---|
horizontal |
boolean |
false |
Mirror left to right. |
vertical |
boolean |
false |
Mirror top to bottom. |
The options object itself is required, even though both options are optional.
Example
import { Jimp } from "jimp";
const image = await Jimp.read("selfie.jpg");
// Undo the mirroring of a front cameraimage.flip({ horizontal: true });
await image.write("selfie-fixed.jpg");Flip both ways
Flipping in both directions gives the same result as rotating by 180°:
image.flip({ horizontal: true, vertical: true });// same pixels as image.rotate(180)Try it
Toggle horizontal and vertical.
image.flip({ horizontal: true, vertical: false })Mirror the image horizontally, vertically or both.
horizontal
vertical
Loading Jimp…Drop an image to load it
index.js
import { Jimp } from "jimp"; const image = await Jimp.read("dice.png"); // Change an option to run it await image.write("output.png");
Notes
- The size doesn’t change. Every pixel is moved, none are resampled, so flipping twice restores the original exactly.
- No options does nothing.
flip({})leaves the image as it is. Callingflip()with no argument at all fails validation withInvalid input: expected object, received undefined. - v0 differences. v0 took two booleans:
flip(horizontal, vertical). In v1 pass an object, and themirroralias is gone.