Skip to content
docs
GitHub 4.5M /week v2.2.0
Blur & effects

blur()

Apply a fast blur with a radius in pixels.

From @jimp/plugin-blur

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

blur.d.ts
image.blur(r: number): this

blur 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

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

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

Try blur()
image.blur(6)

A fast blur that looks close to a Gaussian blur. r is the radius in pixels.

6px
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

  • 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. r is rounded to the nearest whole number and clamped to 1–256, so blur(2.5) is blur(3), blur(0.2) is blur(1) and blur(1000) is blur(256). For a fractional radius, use gaussian.
  • Invalid radii. r values of 0 or less throw r must be greater than 0, and values that aren’t numbers throw r must be a number.
  • blur or gaussian? gaussian computes 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 256 used to make the whole image transparent black, and radii from about 145 to 256 could leave the result partly transparent. r is now rounded and clamped, and large radii blur correctly. Colors weren’t weighted by alpha, so edges next to transparent pixels faded toward black.