Filters
Node BrowserVisual adjustments and effects: blur, sharpen, and colour operations.
blur
.blur(sigma?: number): Pipeline.blur(sigma?: number): PipelineGaussian blur. sigma controls the blur radius — higher values produce stronger blur.
| Param | Type | Default | Description |
|---|---|---|---|
sigma | number | mild blur | Standard deviation of the Gaussian kernel (0.3–1000) |
// Mild blur (default)
await img('photo.jpg').blur().toBuffer()
// Strong blur
await img('photo.jpg').blur(10).toBuffer()
// Background blur effect
await img('photo.jpg').blur(20).toBuffer()// Mild blur (default)
await img('photo.jpg').blur().toBuffer()
// Strong blur
await img('photo.jpg').blur(10).toBuffer()
// Background blur effect
await img('photo.jpg').blur(20).toBuffer()sharpen
.sharpen(options?: SharpenOptions): Pipeline.sharpen(options?: SharpenOptions): PipelineUnsharp mask sharpening. Recovers detail after resizing.
| Option | Type | Default | Description |
|---|---|---|---|
sigma | number | 1 | Gaussian sigma of the sharpening mask |
m1 | number | 1 | Flat area sharpening strength |
m2 | number | 2 | Jagged area sharpening strength |
// Default sharpening — good for post-resize cleanup
await img('photo.jpg').resize(800).sharpen().toBuffer()
// Custom parameters
await img('photo.jpg').sharpen({ sigma: 1.5, m1: 1, m2: 2 }).toBuffer()// Default sharpening — good for post-resize cleanup
await img('photo.jpg').resize(800).sharpen().toBuffer()
// Custom parameters
await img('photo.jpg').sharpen({ sigma: 1.5, m1: 1, m2: 2 }).toBuffer()median
.median(size?: number): Pipeline.median(size?: number): PipelineMedian filter for noise reduction. Preserves edges better than Gaussian blur.
| Param | Type | Default | Description |
|---|---|---|---|
size | number | 3 | Square kernel size in pixels |
// Default — 3x3 kernel
await img('photo.jpg').median().toBuffer()
// Stronger noise reduction
await img('photo.jpg').median(5).toBuffer()// Default — 3x3 kernel
await img('photo.jpg').median().toBuffer()
// Stronger noise reduction
await img('photo.jpg').median(5).toBuffer()grayscale
.grayscale(): Pipeline.grayscale(): PipelineConvert to greyscale using luminance weights.
await img('photo.jpg').grayscale().toBuffer()
// Greyscale JPEG
await img('photo.jpg').grayscale().jpeg({ quality: 85 }).toBuffer()await img('photo.jpg').grayscale().toBuffer()
// Greyscale JPEG
await img('photo.jpg').grayscale().jpeg({ quality: 85 }).toBuffer()tint
.tint(colour: string | { r: number, g: number, b: number }): Pipeline.tint(colour: string | { r: number, g: number, b: number }): PipelineMerge the image with a solid colour. The image luminance is preserved.
// Hex colour
await img('photo.jpg').tint('#ff6600').toBuffer()
// RGB object
await img('photo.jpg').tint({ r: 255, g: 102, b: 0 }).toBuffer()// Hex colour
await img('photo.jpg').tint('#ff6600').toBuffer()
// RGB object
await img('photo.jpg').tint({ r: 255, g: 102, b: 0 }).toBuffer()negate
.negate(): Pipeline.negate(): PipelineInvert pixel values (photographic negative).
await img('photo.jpg').negate().toBuffer()await img('photo.jpg').negate().toBuffer()brightness
.brightness(factor: number): Pipeline.brightness(factor: number): PipelineMultiply brightness. 1.0 is unchanged.
| Value | Effect |
|---|---|
< 1.0 | Darker |
1.0 | No change |
> 1.0 | Brighter |
// 20% brighter
await img('photo.jpg').brightness(1.2).toBuffer()
// 30% darker
await img('photo.jpg').brightness(0.7).toBuffer()// 20% brighter
await img('photo.jpg').brightness(1.2).toBuffer()
// 30% darker
await img('photo.jpg').brightness(0.7).toBuffer()contrast
.contrast(factor: number): Pipeline.contrast(factor: number): PipelineMultiply contrast. 1.0 is unchanged.
// Increase contrast
await img('photo.jpg').contrast(1.3).toBuffer()
// Reduce contrast (flatten)
await img('photo.jpg').contrast(0.8).toBuffer()// Increase contrast
await img('photo.jpg').contrast(1.3).toBuffer()
// Reduce contrast (flatten)
await img('photo.jpg').contrast(0.8).toBuffer()saturation
.saturation(factor: number): Pipeline.saturation(factor: number): PipelineMultiply colour saturation. 0 produces greyscale, 1.0 is unchanged.
// Vibrant colours
await img('photo.jpg').saturation(1.5).toBuffer()
// Desaturate (muted tones)
await img('photo.jpg').saturation(0.5).toBuffer()
// Full greyscale via saturation
await img('photo.jpg').saturation(0).toBuffer()// Vibrant colours
await img('photo.jpg').saturation(1.5).toBuffer()
// Desaturate (muted tones)
await img('photo.jpg').saturation(0.5).toBuffer()
// Full greyscale via saturation
await img('photo.jpg').saturation(0).toBuffer()Combining filters
Filters chain in order, left to right:
await img('photo.jpg')
.resize(1200)
.brightness(1.05)
.contrast(1.1)
.saturation(1.2)
.sharpen()
.webp({ quality: 85 })
.toBuffer()await img('photo.jpg')
.resize(1200)
.brightness(1.05)
.contrast(1.1)
.saturation(1.2)
.sharpen()
.webp({ quality: 85 })
.toBuffer()