- Write resized output to a sibling temp file and atomically rename into the
cache path so concurrent requests never observe a half-written file (was
surfacing as IDAT CRC / truncated-zlib errors on first load).
- Attempt a lenient PNG re-encode via GD then Imagick's
png:preserve-corrupt-image before Spatie, so pedantically-invalid-but-
intact uploads still resize instead of 500ing.
- Fall back to serving the original bytes on unrecoverable decode errors
(typically truncated uploads) instead of throwing — matches what the
browser already tolerates and avoids 500s on damaged sources.
- Backfill extension via MIME sniff when the model lacks one, early-return
for gif/svg, touch cache hits for LRU-style cleanup, and accept
canvasX/canvasY/offsetX/offsetY for padded-canvas resizes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>