Skip to content
docs
GitHub 4.5M /week v2.2.0
Color

greyscale()

Remove all color from the image.

From @jimp/plugin-color

greyscale turns the image into shades of gray. Each pixel’s gray level is based on how bright its color looks to the eye, so greens stay lighter than blues of the same strength.

Signature

greyscale.d.ts
image.greyscale(): this

greyscale takes no arguments. It changes the image in place and returns it, so you can chain more calls after it.

Example

example.ts
import { Jimp } from "jimp";
const image = await Jimp.read("photo.jpg");
image.greyscale();
await image.write("photo-grey.jpg");

Black and white with more punch

Raise the contrast after removing the color:

example.ts
image.greyscale().contrast(0.25);

Tinted monochrome

To get a single-color look, remove the color and then mix one back in with color:

example.ts
image.greyscale().color([{ apply: "mix", params: [{ r: 40, g: 90, b: 200 }, 40] }]);

For the classic brown tone, use sepia.

Try it

Run the playground to see the result. Hold the compare button to see the original.

Try greyscale()
image.greyscale()

Remove all color, keeping the perceived brightness of each pixel.

This method has no options.

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

  • Luminance weights. The gray value is 0.2126 × R + 0.7152 × G + 0.0722 × B (ITU-R BT.709), rounded to the nearest whole number, and written to all three channels. An orange (200, 100, 50) becomes 118.
  • Calling it twice changes nothing. Pixels that are already gray keep their value, so greyscale() on a gray image leaves it as it is.
  • Raw values. The weights are applied to the stored values, whatever the image’s color space. Grays, black and white are the same in sRGB and Display P3.
  • Alpha is unchanged. Transparent areas stay transparent.
  • Spelling. The method is spelled greyscale; there is no grayscale alias.
  • The same as the greyscale color action. image.color([{ apply: "greyscale" }]) gives exactly the same result, so you can use it inside a longer list of color actions. The desaturate action with 100 gives a different gray, the HSL lightness.
  • The image stays RGBA. The pixels are gray, but the bitmap still has four channels. When you write a PNG, Jimp picks a grayscale PNG automatically if every pixel is gray. See Formats.
  • Changed in 2.0: the gray value is rounded; before, it was rounded down, so many pixels came out one level darker and calling greyscale() again could darken them further.