Skip to content

finaIcutpro/optima

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

optima

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.

highlights

  • libvips for fast resize and compression
  • libmicrohttpd for low-latency http
  • smart format negotiation: webp if supported, fallback otherwise
  • configurable timeouts and limits

dependencies

install system libs (macos with homebrew):

brew install cmake libvips libmicrohttpd curl

build & run

cmake -S . -B build
cmake --build build --config Release
./build/optima

env 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

next.js integration

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

example

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.

About

a blazing-fast image optimization microservice for next.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors