KXkonstantinos.xafis
Full-Stack & CloudflareMaintained2024

Byz-ImageCompression

BunTypeScriptsharpDocker

Overview

The school platform needed every uploaded image to reach web-ready size without manual intervention. This microservice guarantees a fixed target: roughly 40 KB per image.

What I built

A single POST endpoint on Bun.serve using sharp (libvips). The logic reads image metadata first: if the source is already within budget it is returned as-is; otherwise a shrink factor is computed from the file size (sqrt(size/40KB)/2), halving each dimension to quarter the pixel area, and the image is resized and re-encoded.

It shares the ecosystem’s security pattern: CORS preflight, referer allowlist, and session-proxy authentication against the school backend — plus the same typed EndpointResponse union as its sibling services, so all three services speak the same API language.

Technical highlights

Outcome

Runs in Docker alongside the school platform, called on upload.