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

opaque()

Make every pixel fully opaque.

From @jimp/plugin-color

opaque removes all transparency by setting the alpha channel of every pixel to 255. Use it when you need an image without transparency, or to see the colors hidden in transparent areas.

Signature

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

opaque 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("sticker.png");
image.opaque();
console.log(image.hasAlpha()); // false

Put a transparent image on a solid background

opaque reveals whatever color the transparent pixels store, which is often black. To flatten onto a chosen color instead, composite the image onto a new one:

example.ts
import { Jimp } from "jimp";
const image = await Jimp.read("sticker.png");
const flat = new Jimp({ width: image.width, height: image.height, color: 0xffffffff });
flat.composite(image, 0, 0);
await flat.write("sticker-on-white.jpg");

Try it

Run the playground to see the result. The dice image stores black in its transparent background, so it turns black.

Try opaque()
image.opaque()

Set every pixel's alpha to 255. Transparent areas show whatever color they store, often black.

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

  • Colors are unchanged. Only alpha changes. Partly transparent pixels show their full stored color, so soft edges can look harsh.
  • opaque and hasAlpha. After opaque, hasAlpha returns false, and encoders that check for transparency (such as PNG) write the image without an alpha channel.
  • The opposite. To make an image partly transparent, use opacity or fade.