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)image(input)
Section titled “image(input)”Entry point. Accepts a File (browser) or Buffer / Uint8Array (Node.js).
// Browserimport { image } from 'beautiful-image'const pipeline = image(file)
// Node.jsimport { image } from 'beautiful-image/node'const pipeline = image(buffer).resize(width)
Section titled “.resize(width)”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).sharpen(sigma?)
Section titled “.sharpen(sigma?)”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.5image(file).resize(1200).sharpen(2.5) // stronger.blur(sigma)
Section titled “.blur(sigma)”Applies a Gaussian blur.
| Parameter | Type | Description |
|---|---|---|
sigma |
number |
Blur radius. Higher = more blurred. |
image(file).blur(8) // blurred preview / thumbnail.brightness(value)
Section titled “.brightness(value)”Adjusts brightness.
| Parameter | Type | Range | Description |
|---|---|---|---|
value |
number |
-100..100 |
Positive = brighter |
image(file).brightness(20).contrast(value)
Section titled “.contrast(value)”Adjusts contrast.
| Parameter | Type | Range | Description |
|---|---|---|---|
value |
number |
-100..100 |
Positive = more contrast |
image(file).contrast(-10).hueRotate(degrees)
Section titled “.hueRotate(degrees)”Rotates the hue of every pixel.
| Parameter | Type | Range | Description |
|---|---|---|---|
degrees |
number |
-180..180 |
Degrees to rotate hue |
image(file).hueRotate(120).grayscale()
Section titled “.grayscale()”Converts the image to black and white. No parameters.
image(file).grayscale().invert()
Section titled “.invert()”Inverts all colors. No parameters.
image(file).invert().toJpeg(quality) terminal
Section titled “.toJpeg(quality) terminal”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)