Skip to content
YEMS edited this page Oct 22, 2026 · 6 revisions

Image processing

English · 한국어

Client v1.2.0 converts JPEG, PNG, WebP, HEIC, and HEIF to WebP on-device. It does not send originals to a conversion server. Inputs larger than 2 MiB are allowed, but the final WebP must be at most 2,000,000 bytes.

Input and output rules

  • At most four photos per entry. A selection exceeding remaining slots is rejected without changing existing photos. Convert sequentially; report individual failures and keep successful/existing photos.
  • Add, remove, and replace photos individually. Replacement preserves order. While existing photos are loading or failed, saving is blocked. Canceling an edit does not alter stored photos.
  • Two photos use side-by-side layout; three use one large left photo and two right photos; four use a 2×2 grid. The viewer supports full images, previous/next, arrow keys, and Escape.
  • Opening the viewer prepares keyboard handling and focuses its close button before paint. Opening/closing restores focus without scrolling the timeline.
  • Draft restoration restores text; unsaved photo attachments trigger a navigation warning.
  • Input limits: 50 MiB, 50,000,000 pixels, and at most 32,768 pixels per side.
  • Preserve aspect ratio and reduce the long side to at most 1,000px; do not upscale. Low-resource mode starts at 800px.
  • Try qualities 0.82 → 0.70 → 0.55 → 0.40 at each size, then reduce the long side through 1,000 → 800 → 600 → 400px if necessary. Reject images still over the limit, empty output, or PNG output mislabeled as WebP.
  • Re-encode pixels through Canvas without copying original EXIF/GPS or XMP. Clean up bitmaps and canvases on success and failure. Block duplicate selection/saving during conversion; discard stale results after canceling, changing edit targets, or locking.

WebP fallback

WebP display support and Canvas encoding support are different. Inspect the actual toBlob MIME type. If Canvas returns PNG, lazily load @jsquash/webp 1.5.0 and encode resized pixels using WebAssembly in a dedicated Worker. Apply the same size/quality limits, validate RIFF/WebP signatures, and terminate the Worker afterward.

CSP needs 'wasm-unsafe-eval' for WebAssembly, without JavaScript 'unsafe-eval' or 'unsafe-inline'. Apply generated out/_headers on the host. Encoder code/WASM may require a connection on first use or after an offline restart. Report loading/execution failures so users can retry.

HEIC/HEIF fallback

Detect HEIF from MIME, case-insensitive .heic/.heif, or ftyp brands. Try native browser decoding first, then lazily load heic-to/csp 1.5.2 in an on-device Worker. Ordinary JPEG/PNG/WebP inputs do not load it. Use the first image returned by the library; this does not promise full multi-image, video, Live Photo, or HEIF codec support. Invalid/unsupported files produce an error.

The host must honor worker-src 'self' blob: from public/_headers. First fallback use needs the decoder assets; offline restart behavior and physical-device support require separate verification.

Memory limits and verification

Before HEIF decoding, inspect ispe within a meta box of at most 2 MiB. Reject missing, malformed, or truncated metadata and inspect at most 256 top-level boxes. Also check decoded dimensions for all formats. These limits bound inputs, resolution, and retries, not peak browser/decoder memory. JPEG/PNG/WebP native decoders can allocate full pixels before dimension checks. High-resolution/HDR/rotated/multi-image inputs and prolonged use require physical iOS/Android checks.

In web/, use npm run build, npm run test:unit, and npm run test:browser. Install browsers with npx playwright install --with-deps chromium firefox webkit. Unit checks cover limits, quality/size order, portrait/low-resource cases, cleanup, and HEIF detection/metadata. Browser checks use real CSP and actual conversions: PNG over 2 MiB, forced PNG-to-WASM fallback, HEIC fixtures, padded HEIF, corrupted input, duplicate actions, and cancellation. Check signatures, MIME, bytes, dimensions, metadata removal, upload absence, and CSP violations.

Windows Playwright WebKit does not substitute for iPhone testing. Decoder: heic-to, LGPL-3.0 with embedded libheif. Encoder: jSquash, Apache-2.0 with embedded libwebp. Fixture provenance is maintained with the tests.

Clone this wiki locally