blur softens the image by averaging each pixel with its neighbors.
It looks close to a Gaussian blur but runs much faster, especially at large radii, so it’s the one to reach for unless you need an exact Gaussian.
Signature
image.blur(r: number): thisblur changes the image in place and returns it, so you can chain more calls after it.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
r |
number |
required | The blur radius in pixels, greater than 0. It’s rounded to a whole number and clamped to 1–256. |
Example
import { Jimp } from "jimp";
const image = await Jimp.read("photo.jpg");
image.blur(5);
await image.write("photo-blurred.jpg");Blur part of an image
blur always works on the whole image.
To blur one area, such as a face or a license plate, blur a cropped copy and draw it back on top:
const area = { x: 40, y: 30, w: 120, h: 120 };
const patch = image.clone().crop(area).blur(10);
image.composite(patch, area.x, area.y);Try it
Drag the slider to change r. The code panel shows the call that produced the image.
image.blur(6)A fast blur that looks close to a Gaussian blur. r is the radius in pixels.
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
- Transparency is handled. Colors are weighted by their alpha while blurring, so transparent pixels don’t leave a dark fringe around the edges of a shape.
- Edges are extended. Near the border, pixels outside the image count as copies of the nearest edge pixel, so the edges don’t fade to black.
- Whole-pixel radii.
ris rounded to the nearest whole number and clamped to1–256, soblur(2.5)isblur(3),blur(0.2)isblur(1)andblur(1000)isblur(256). For a fractional radius, usegaussian. - Invalid radii.
rvalues of0or less throwr must be greater than 0, and values that aren’t numbers throwr must be a number. blurorgaussian?gaussiancomputes a true Gaussian blur. It’s a little smoother, but it gets much slower as the radius grows. For most images the difference isn’t visible.- Changed in 2.0: a fractional radius or one above
256used to make the whole image transparent black, and radii from about145to256could leave the result partly transparent.ris now rounded and clamped, and large radii blur correctly. Colors weren’t weighted by alpha, so edges next to transparent pixels faded toward black.