Skip to content

Image engine

The @stirling-image/image-engine package handles all non-AI image operations. It wraps Sharp and runs entirely in-process with no external dependencies.

Operations

resize

Scale an image to specific dimensions or by percentage.

ParameterTypeDescription
widthnumberTarget width in pixels
heightnumberTarget height in pixels
fitstringcover, contain, fill, inside, or outside
withoutEnlargementbooleanIf true, won't upscale smaller images
percentagenumberScale by percentage instead of absolute dimensions

You can set width, height, or both. If you only set one, the other is calculated to maintain the aspect ratio.

crop

Cut out a rectangular region from the image.

ParameterTypeDescription
leftnumberX offset from the left edge
topnumberY offset from the top edge
widthnumberWidth of the crop area
heightnumberHeight of the crop area

rotate

Rotate the image by a given angle.

ParameterTypeDescription
anglenumberRotation angle in degrees (0-360)
backgroundstringFill color for the exposed area (default: transparent or white)

flip

Mirror the image horizontally or vertically.

ParameterTypeDescription
directionstringhorizontal or vertical

convert

Change the image format.

ParameterTypeDescription
formatstringTarget format: jpeg, png, webp, avif, tiff, gif
qualitynumberCompression quality (1-100, applies to lossy formats)

compress

Reduce file size while keeping the same format.

ParameterTypeDescription
qualitynumberTarget quality (1-100)
formatstringOptional format override

strip-metadata

Remove EXIF, IPTC, and XMP metadata from the image. Useful for privacy before sharing photos publicly. Takes no parameters.

Color adjustments

These operations modify the color properties of an image. Each takes a single numeric value.

OperationParameterRangeDescription
brightnessvalue-100 to 100Adjust brightness
contrastvalue-100 to 100Adjust contrast
saturationvalue-100 to 100Adjust color saturation

Color filters

These apply a fixed color transformation. They take no parameters.

OperationDescription
grayscaleConvert to grayscale
sepiaApply a sepia tone
invertInvert all colors

Color channels

Adjust individual RGB color channels.

ParameterTypeDescription
rednumberRed channel adjustment (-100 to 100)
greennumberGreen channel adjustment (-100 to 100)
bluenumberBlue channel adjustment (-100 to 100)

Format detection

The engine detects input formats automatically from file headers, not just file extensions. This means a .jpg file that is actually a PNG will be handled correctly.

Supported input formats: JPEG, PNG, WebP, AVIF, TIFF, GIF, SVG, RAW (via libraw).

Metadata extraction

The info tool returns image metadata:

json
{
  "width": 1920,
  "height": 1080,
  "format": "jpeg",
  "size": 245678,
  "channels": 3,
  "hasAlpha": false,
  "dpi": 72,
  "exif": { ... }
}