fade makes the whole image more transparent by removing a fraction f of every pixel’s opacity.
0 leaves the image unchanged, 0.3 removes 30% of the opacity and 1 makes the image fully transparent.
Signature
image.fade(f: number): thisfade changes the image in place and returns it, so you can chain more calls after it.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
f |
number |
required | How much opacity to remove, from 0 (none) to 1 (all of it). |
Example
import { Jimp } from "jimp";
const image = await Jimp.read("logo.png");
image.fade(0.7);
await image.write("logo-faded.png");Fade between two images
Draw a faded copy of one image on top of another to blend them:
import { Jimp } from "jimp";
const before = await Jimp.read("before.png");const after = await Jimp.read("after.png");
before.composite(after.clone().fade(0.6), 0, 0);
await before.write("blend.png");Try it
Drag the slider to change f. Transparent areas show the background through them.
image.fade(0.5)Make every pixel more transparent: 0 changes nothing, 1 makes it invisible.
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
- Same as
opacity(1 - f).fadecallsopacitywith1 - f, sofade(0.3)andopacity(0.7)give identical results. Pick whichever reads better. - Relative to the current alpha. A pixel with alpha
200faded by0.3ends up at140. Already transparent pixels stay transparent. - Colors are unchanged. Only alpha changes, so the effect is lost if you save to a format without transparency, such as JPEG.
- Errors. An
fthat isn’t a number throwsf must be a number. A value outside0to1throwsf must be a number from 0 to 1.