OptionalformatTarget output format. Default: 'auto' (converts PNG/JPEG to WebP).
OptionalqualityEncoder quality from 0.0 (worst) to 1.0 (best). Default: 0.8.
OptionalmaxTarget output file size in megabytes. When set, the library runs a binary
search over quality values (up to 6 passes) to find the highest quality
that produces output ≤ maxSizeMB. Applies to lossy formats only
(WebP, JPEG, AVIF). PNG is lossless and ignores this option.
If the target cannot be reached at minimum quality (0.05), the smallest achievable result is returned with a console warning.
OptionalmaxResize output width to at most this many pixels (maintains aspect ratio).
OptionalmaxResize output height to at most this many pixels (maintains aspect ratio).
OptionalminScale up if output width is below this value (maintains aspect ratio).
OptionalminScale up if output height is below this value (maintains aspect ratio).
OptionalwidthExact output canvas width in pixels. Use with resize to control fitting.
OptionalheightExact output canvas height in pixels. Use with resize to control fitting.
OptionalresizeResize mode when both width and height are set.
'contain' (default): scale to fit within the canvas, letterbox if needed.'cover': scale to fill the canvas, cropping the overflow.'fill': stretch to fill the canvas exactly, ignoring aspect ratio.'inside': scale down to fit within bounds; never upscales; no letterbox.'outside': scale to cover bounds without cropping; may exceed bounds in one dimension.'none': draw the image at its current size; canvas is cropped/padded.OptionalpositionAnchor point for letterboxing (contain) or cropping (cover).
Default: 'center'. Accepts: 'center', 'top', 'right', 'bottom',
'left', 'top-left', 'top-right', 'bottom-left', 'bottom-right'.
Also accepts compass direction aliases: 'north', 'east', 'south', 'west', etc.
OptionalwithoutWhen true, the image is never upscaled beyond its original dimensions,
even when the target canvas is larger. Also disables minWidth/minHeight.
Default: false.
OptionalconvertMIME type(s) eligible for auto format conversion (e.g. 'image/png').
When the input's MIME type matches one of these AND the file size is below
convertSize, the format is locked to the input format (no conversion).
Default: [] (no restriction).
OptionalconvertMinimum file size (bytes) that triggers convertTypes auto-conversion.
Files below this threshold keep their original format.
Default: 5242880 (5 MB).
OptionalbeforeCalled on the canvas context after the canvas is created and filled, but before the image bitmap is drawn. Useful for applying background colours or watermarks. Browser fast path only (no-op on FFmpeg / Node paths).
OptionaldrewCalled on the canvas context after the image bitmap has been drawn, but before the canvas is encoded. Useful for overlays or post-processing. Browser fast path only (no-op on FFmpeg / Node paths).
OptionalcheckWhen true (default), EXIF orientation is applied automatically so the
image is upright. Set to false to preserve the raw pixel orientation.
OptionalretainWhen true, the original EXIF metadata is re-injected into the JPEG output.
Only applies to JPEG input compressed to JPEG output on the browser fast path.
Default: false.
OptionalpreserveWhen true, EXIF/metadata is preserved in the output. Default: false (stripped).
OptionalstrictIf the compressed image is larger than the original, return the original. Default: false.
OptionaluseExplicitly force Web Worker usage (true) or Main Thread usage (false). If omitted, the library chooses based on file size and operation type.
OptionalonCalled with progress 0–100 during heavy-path (FFmpeg) operations.
OptionalsignalCancel the operation. Throws AbortError when signalled.
Options for compressImage().