Color
exposure()
Brighten or darken by stops, like a camera's exposure setting.
From @jimp/plugin-color
exposure makes an image lighter or darker by a number of stops, like the exposure slider in a photo editor.
Each stop doubles or halves the light, so 1 is one stop brighter, -1 one stop darker and 0 leaves the image unchanged.
Signature
image.exposure(stops: number): thisexposure changes the image in place and returns it, so you can chain more calls after it.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
stops |
number |
required | How many stops to change the exposure by. Positive values brighten, negative values darken. Fractions such as 0.5 work. |
Example
import { Jimp } from "jimp";
const image = await Jimp.read("photo.jpg");
image.exposure(1); // one stop brighter
await image.write("photo-brighter.jpg");Darken an image
Use a negative number of stops:
image.exposure(-0.5); // half a stop darkerTry it
Drag the slider to change stops. Compare it with brightness: the highlights keep their detail for longer.
image.exposure(1)Change the exposure in stops, in linear light: 1 doubles the light and -1 halves it.
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
- It works in linear light. Image files store values on a curve, not in proportion to the light they stand for.
exposuredecodes each channel to linear light with the image’s tone curve, multiplies it by2 ** stops, and encodes it back to the nearest 8-bit value. Shadows and highlights change the way they would with a longer or shorter exposure. exposureorbrightness?brightnessmultiplies the stored values directly. For a mid-gray128,exposure(1)gives176, whilebrightness(2)gives255. Useexposurefor photos andbrightnesswhen you want a plain multiplier.- Color spaces. The tone curves come from the image’s ICC profile, such as Display P3 or Adobe RGB, and are sRGB’s for images without one. See Color spaces.
- Results are clamped. Channels that go over
255become255, so large positive values turn the image white and large negative values turn it black. Black stays black at any setting. - Alpha is unchanged.
- Errors. A
stopsthat isn’t a number throws aZodError. - Added in 2.0.