Skip to content
docs
GitHub 4.5M /week v2.2.0
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

brightness.d.ts
image.brightness(val: number): this

brightness 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

example.ts
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:

example.ts
image.brightness(0.6); // 40% darker

Try it

Drag the slider to change val. Values above 1 brighten and values below 1 darken.

Try brightness()
image.brightness(1.3)

Multiply each color channel by a factor. 1 leaves the image unchanged.

1.3
Loading Jimp…Drop an image to load it
PNG
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 0 gives 0, so brightness can’t lift pure black. To move every pixel toward white instead, use the lighten or tint action of color.
  • Alpha is unchanged. Only the red, green and blue channels are multiplied.
  • Errors. A val that isn’t a number throws val must be numbers. There is no upper limit.
  • brightness or exposure? brightness multiplies the stored 8-bit values, so a factor of 2 turns a mid-gray 128 into white. exposure multiplies the light those values stand for, as a camera would: exposure(1) doubles the light and turns 128 into 176, keeping detail in the highlights.
  • For fine control of light and dark tones, contrast and normalize often give better results than a single multiplier.