A tiny Squoosh like image compressor in a single 100-line file, powered by Bun's built-in image processing. No dependencies.
bun squash.ts
# → http://localhost:3000(Use bun --hot squash.ts for live reload while editing.)
- Drop an image onto the frame (or click to pick one).
- Choose a format (webp / jpeg / png) and drag the quality slider.
- Drag the divider to compare the original (left) against the compressed result (right).
- Hit Download to save the compressed file.
It recompresses on load, when you release the quality slider, and when you switch format.
The browser POSTs the raw image bytes to /compress?format=…&quality=…. The server pipes them through Bun.Image and streams the result back:
const img = new Bun.Image(await req.arrayBuffer())
const out = img[fmt](fmt === 'png' ? { compression: 9 } : { quality })
return new Response(out) // Content-Type set automaticallyThat is the whole engine: no sharp or native install step.
- Everything (server + UI) lives in
squash.ts.
