a blazing-fast c image optimization microservice for next.js. reduces images by over 80%, responds in less than 15ms.
fetches remote images, resizes on demand, optimizes to webp/jpeg/png.
- libvips for fast resize and compression
- libmicrohttpd for low-latency http
- smart format negotiation: webp if supported, fallback otherwise
- configurable timeouts and limits
install system libs (macos with homebrew):
brew install cmake libvips libmicrohttpd curlcmake -S . -B build
cmake --build build --config Release
./build/optimaenv vars:
- optima_port (default 8080)
- optima_fetch_timeout_ms (default 5000)
- optima_max_download_bytes (default 26214400, 1-100 mib)
health check: curl http://localhost:8080/healthz
configure custom loader:
// next.config.js
module.exports = {
images: {
loader: 'custom',
remotePatterns: [{ protocol: 'https', hostname: 'melonly.xyz' }],
customLoader: ({ src, width, quality }) => {
const params = new URLSearchParams();
params.set('url', src);
params.set('w', String(width));
if (quality) params.set('q', String(quality));
return `https://optima.melonly.xyz${src}?${params.toString()}`;
},
},
};for local dev, use http://localhost:8080
curl "http://localhost:8080?url=https://melonly.xyz/img/modpanelpreview.jpg&w=1200&q=80" \
--output optimized.webp \
--header "Accept: image/webp,image/*;q=0.8"streams remote image, resizes with lanczos, compresses, returns optimized image with caching headers.