Skip to content

API Reference

All methods are available in both the browser (beautiful-image) and Node.js (beautiful-image/node) builds. Methods are chainable and return this until a terminal encode method is called.

const result = await image(file)
.resize(1200)
.sharpen()
.brightness(10)
.toJpeg(80)

Entry point. Accepts a File (browser) or Buffer / Uint8Array (Node.js).

// Browser
import { image } from 'beautiful-image'
const pipeline = image(file)
// Node.js
import { image } from 'beautiful-image/node'
const pipeline = image(buffer)

Resizes the image to the given width, maintaining the original aspect ratio.

Parameter Type Description
width number Target width in pixels
image(file).resize(1200)

Applies an unsharp mask to recover detail lost during resize.

Parameter Type Default Description
sigma number 1.5 Sharpening strength. Higher = stronger.
image(file).resize(1200).sharpen() // default sigma 1.5
image(file).resize(1200).sharpen(2.5) // stronger

Applies a Gaussian blur.

Parameter Type Description
sigma number Blur radius. Higher = more blurred.
image(file).blur(8) // blurred preview / thumbnail

Adjusts brightness.

Parameter Type Range Description
value number -100..100 Positive = brighter
image(file).brightness(20)

Adjusts contrast.

Parameter Type Range Description
value number -100..100 Positive = more contrast
image(file).contrast(-10)

Rotates the hue of every pixel.

Parameter Type Range Description
degrees number -180..180 Degrees to rotate hue
image(file).hueRotate(120)

Converts the image to black and white. No parameters.

image(file).grayscale()

Inverts all colors. No parameters.

image(file).invert()

Encodes the processed image as JPEG and returns a Promise. This is the terminal method, it triggers processing and must be awaited.

Parameter Type Range Description
quality number 1..100 JPEG quality. 80 is a good default.

Returns (browser):

{
blob: Blob
originalSize: number
optimizedSize: number
compressionRatio: number
width: number
height: number
}

Returns (Node.js):

{
data: Buffer
originalSize: number
optimizedSize: number
compressionRatio: number
}
const result = await image(file).resize(1200).sharpen().toJpeg(80)