Skip to content

Options and results ​

Options ​

OptionDefaultMeaning
mode"balanced"lossless, visually-lossless, balanced, fast
minQuality0.99 / 0.975SSIM threshold for perceptual modes
maxOutputBytes–Upper bound; reported in unmetConstraints when it cannot be met without violating quality
maxWidthOrHeight–Downscale the longest side (Lanczos3, linear light, premultiplied alpha)
allowLossyResizefalsePermit resizing in lossless mode
targetFormat"auto"auto, original, jpeg, png, webp, avif
autoFormatsall four (fast: no AVIF)Formats auto may choose
allowFormatConversiontruefalse keeps the input format
maxCandidates10 / 16 / 4 / 5Encode budget (balanced / visually-lossless / lossless / fast)
searchStrategy"binary"fixed: one encode per format
preserveMetadatatrueKeep EXIF/XMP/ICC; false removes EXIF (incl. GPS) and XMP
preserveAnimationtruefalse permits flattening animations to the first frame
minSavingsRatio0.02Return the original unless re-encoding saves at least this share
markOutputfalseTag lossy JPEG/WebP outputs (~20 bytes) so later runs do not re-encode them. The CLI and MCP server turn it on
reoptimizefalseRe-encode inputs that carry that tag anyway (each lossy pass loses a little more)
maxInputBytes100 MiBChecked before the file is read
maxInputPixels50 MPChecked from the header before decoding
onUnmetConstraints"best-effort"throw rejects with CONSTRAINTS_UNSATISFIABLE
signal–AbortSignal
onProgress–Progress callback

Options are constraints, not promises. When they conflict with the image (JPEG requested for a transparent image, conversion of an animated GIF, resizing in lossless mode) the call fails with INCOMPATIBLE_OPTIONS and a message that says which option to change.

Result ​

Field
blob, fileName, mimeTypeOutput ready to upload; type and extension match the bytes
usedOriginaltrue when blob is the unmodified input
originalFormat, outputFormatDetected from content
originalBytes, outputBytes, sizeReductionRatio1 − out/in. Can be negative only when the original is not an allowed result (explicit targetFormat, or resizing)
width, height, originalWidth, originalHeightAs displayed (after EXIF orientation)
qualityMetric, qualityMetricNameSSIM, or 1 with "exact"
codec, settingsEncoder and settings of the chosen candidate
categoryphoto, screenshot, text-graphic, illustration, transparent-illustration, gradient
candidatesEvery encode tried (size, quality, time, pass/fail; proxy: true for tile-mosaic search)
constraintsMet, unmetConstraintsWhich constraints could not be met
metadataWhat happened to EXIF, XMP, ICC and orientation
fallbacksCodec or runtime fallbacks used
warningsHuman-readable notes, e.g. “AVIF output skipped: …”
durationMs, mode

Progress ​

onProgress receives { stage, progress, candidatesTried, candidateBudget, bestBytes? }. Stages, in order: reading → probing → decoding → (resizing) → analyzing → encoding → finalizing → done. progress is a rough 0..1 value; bestBytes is the smallest valid candidate so far — useful for an “estimated reduction” display while the search runs.