Color
brightness()
Multiply every color channel. 1 leaves the image unchanged.
From @jimp/plugin-color
brightness makes an image lighter or darker by multiplying the red, green and blue channels of every pixel by the same factor.
1 leaves the image unchanged, 1.5 makes it 50% brighter and 0.5 makes it 50% darker.
Signature
image.brightness(val: number): thisbrightness changes the image in place and returns it, so you can chain more calls after it.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
val |
number |
required | The factor to multiply each channel by. Above 1 brightens, below 1 darkens, 0 or less makes the image black. |
Example
import { Jimp } from "jimp";
const image = await Jimp.read("photo.jpg");
image.brightness(1.3); // 30% brighter
await image.write("photo-bright.jpg");Darken an image
Use a factor between 0 and 1:
image.brightness(0.6); // 40% darkerTry it
Drag the slider to change val. Values above 1 brighten and values below 1 darken.
image.brightness(1.3)Multiply each color channel by a factor. 1 leaves the image unchanged.
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
- Results are clamped. Each channel is multiplied and then limited to
0–255, so bright areas turn white quickly at large factors and the detail in them is lost. - Black stays black. Multiplying
0gives0, sobrightnesscan’t lift pure black. To move every pixel toward white instead, use thelightenortintaction ofcolor. - Alpha is unchanged. Only the red, green and blue channels are multiplied.
- Errors. A
valthat isn’t a number throwsval must be numbers. There is no upper limit. brightnessorexposure?brightnessmultiplies the stored 8-bit values, so a factor of2turns a mid-gray128into white.exposuremultiplies the light those values stand for, as a camera would:exposure(1)doubles the light and turns128into176, keeping detail in the highlights.- For fine control of light and dark tones,
contrastandnormalizeoften give better results than a single multiplier.