SuperAPI AI Directory

optiq

Optiq is a browser-side image optimization tool that runs in a Web Worker via WASM codecs, encoding a set of candidates for each image (jpegli, libwebp, libavif, oxipng) and measuring each candidate, returning the smallest output that satisfies the specified constraint (lossless, visually lossless, or balanced mode). It supports browsers, Node.js, CLI, and an MCP server, and provides an S3 upload helper.

Open website

About this tool

Optiq is a browser-side image optimizer designed to provide the smallest possible output for upload scenarios while satisfying measurable lossless or SSIM constraints. It uses codecs compiled to WebAssembly (jpegli, libwebp, libavif, oxipng), runs in a Web Worker, and the main thread is only responsible for sending a Blob and receiving an ArrayBuffer.

Key capabilities:

  • Encodes a bounded set of candidates for each image, measures each candidate, and returns the smallest output that satisfies the constraint.
  • Supports three constraint modes: lossless (decoded pixels including alpha are exactly identical to the input), visually lossless (SSIM ≥ 0.99, configurable), and balanced (default, SSIM ≥ 0.975, smaller search budget, faster AVIF preset). AVIF uses a stricter SSIM threshold than JPEG and WebP, calibrated against the SSIMULACRA2 metric.
  • Results include the selected codec/settings, all candidates tried, measured quality, warnings, fallbacks, and unmet constraints.
  • The same engine can run in Node, and provides a CLI (npx optiq-image) and an MCP server for AI agents (optiq-mcp).
  • In the browser, work runs in a thread, keeping the main thread responsive.
  • Provides an S3 upload helper, with compression optional and non-blocking for uploads.

Usage:

  • Browser requirements: ES2022, module Workers, and WebAssembly (Chrome/Edge 80+, Firefox 114+, Safari 15+). AVIF output is only useful when the audience can decode AVIF (Chrome 85+, Firefox 93+, Safari 16.4+); otherwise it can be removed via autoFormats: ["jpeg", "png", "webp"].
  • Bundler setup: webpack 5 and Parcel 2 natively understand new Worker(new URL("./worker.js", import.meta.url), { type: "module" }) and new URL("*.wasm", import.meta.url). Otherwise, pass workerFactory to createCompressor. Each codec is a separate chunk, fetched on first use (AVIF is about 3.5 MB, others 35–350 KB).
  • Workers can be explicitly controlled via createCompressor({ maxWorkers, workerFactory, codecFallback, allowMainThread, recycleAfterPixels }).
  • Progress stages: reading → probing → decoding → (resizing) → analyzing → encoding … → finalizing → done.
  • Error codes include INVALID_INPUT, UNSUPPORTED_FORMAT, MALFORMED_INPUT, INPUT_TOO_LARGE, INVALID_OPTIONS, INCOMPATIBLE_OPTIONS, CONSTRAINTS_UNSATISFIABLE, CODEC_UNAVAILABLE, UNSUPPORTED_ENVIRONMENT, WORKER_ERROR, ABORTED.
  • Provides a React hook, CLI, and Vite plugin examples.
  • The MCP server (optiq-mcp) is a local stdio server based on the TypeScript MCP SDK, providing two tools for AI agents, with JSON configuration suitable for MCP clients such as Claude Desktop and Cursor.
  • For agents driving the CLI, an Agent Skill is provided. The documentation site has llms.txt.

Use cases:

  • Image optimization before browser-side upload to reduce transmitted bytes.
  • Image compression that needs to satisfy specific quality constraints (lossless or SSIM).
  • Batch image processing in a Node.js environment or CLI.
  • Letting AI agents optimize images in a project via the MCP server.

Limitations:

  • Lossless means decoded RGBA equality, verified against the decoders used by Optiq. JPEG decoders are not bit-exact across implementations, so "lossless" for JPEG input is only a byte-level container rewrite (metadata removal), never a re-encode.
  • Transparency is never discarded: when any pixel has alpha < 255, JP is excludedEG.
  • Orientation: EXIF orientation is applied to the pixels of the re-encoded output (the tag is reset to 1); container-level output is preserved.
  • Color: ICC profiles are carried into JPEG/PNG/WebP output. AVIF output is tagged as sRGB and is not used for images with non-sRGB profiles. The sRGB profile is dropped only when preserveMetadata: false (or for AVIF output, where the nclx sRGB tag is equivalent). No color conversion is performed.
  • Metadata: preserved by default. AVIF output is skipped when EXIF/XMP must be preserved (there is no AVIF metadata writer). When preserveMetadata: false, EXIF (including GPS), XMP, comments, and trailing data are removed.
  • Animations are never silently flattened.
  • SSIM is a proxy for perception, not perception itself: it underestimates banding and chroma bleeding in smooth gradients. Validate thresholds on your own content.
  • Memory: large images require hundreds of MB inside a worker. WASM memory is returned by terminating the worker, which happens automatically after tasks above 8 MP.
  • Speed: the search requires multiple encodes. When latency matters, use balanced, lower maxCandidates, searchStrategy: "fixed", or remove AVIF from autoFormats.
  • Benchmarks show that Optiq is not universally better than alternatives; the trade-offs (size vs. time vs. memory) are listed by category.
  • Gradients remain a weakness, scoring 64–72 across all modes and codecs.
  • License Apache-2.0; codecs come from jpegli (BSD-3) and jSquash (Apache-2.0 wrapper), including libjpeg-turbo, libwebp, libavif, libaom, and Rust crates. No GPL or AGPL code is included.
  • Toolchain: Node ≥ 20, pnpm 11, Playwright Chromium. No Rust toolchain is required; all WASM comes from prebuilt pinned jSquash packages.