"A deep-dive into building a sub-300ms image optimization microservice on Alpine Linux using libvips and WebP — with real benchmark numbers and free API access."
tags: webdev, python, performance, api
cover_image: https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=1200
canonical_url:

series:

How I Cut 360° Panorama & E-Commerce Image Sizes by 80% Using Alpine Linux & WebP

TL;DR: I built a free, public API that converts any image — including 12 MB 360° equirectangular panoramas — to WebP in under 300 ms. This post shows how it was built and how you can use it today.

The Problem Nobody Talks About

If you've ever shipped a 360° virtual tour, you know the pain. A single equirectangular panorama can weigh 10–15 MB as a JPEG. Load six of them and your page is dragging 90 MB of images across a mobile connection.

The same story plays out on e-commerce sites: PNG product photos averaging 3–4 MB each, multiplied by a 50-item catalogue page.

WebP fixes this. Google's format reliably delivers 80–92% smaller files with no visible quality loss. The problem has always been tooling — batch conversion pipelines are fiddly, server-side processing is slow if you use ImageMagick naively, and squeezing this into a CI/CD pipeline requires more DevOps than most teams want.

So I built an API.

Architecture: Why Alpine Linux + libvips?

The microservice runs as a Docker container based on alpine:3.19. Here's why each choice matters:

Layer Choice Why
Base OS Alpine Linux 5 MB image; minimal attack surface; fast cold starts
Image lib libvips 10× faster than ImageMagick; low memory; streaming I/O
Runtime Python 3.12 FastAPI + pyvips bindings; async I/O for concurrent reqs
Transport WebP base64 No temp file storage; stateless; JSON-native response

The key insight: libvips processes images as a pipeline of operations rather than loading the entire bitmap into RAM. A 12 MB JPEG becomes a 920 KB WebP while peak memory stays under 80 MB.

Benchmark Numbers (Real API, Real Images)

I ran these against the live endpoint hosted on Railway + RapidAPI:

Test 1: 360° Equirectangular Panorama (12 MB JPEG, 8192×4096) → 920 KB WebP in 290 ms — 92% size reduction Test 2: E-Commerce product photo (3.4 MB PNG, 2000×2000, white bg) → 310 KB WebP in 180 ms — 91% size reduction Test 3: Hero banner (1.8 MB JPEG, 1920×1080) → 195 KB WebP in 140 ms — 89% size reduction Test 4: Batch of 50 thumbnails (85 MB total PNGs) → 7.2 MB WebP in ~8 s — 92% size reduction 

Integration: 3 Languages, Copy-Paste Ready

Python

import requests, base64, os API_KEY = os.environ["RAPIDAPI_KEY"] payload = { "image_url": "https://example.com/panorama.jpg", "quality": 80, "max_width": 4096, } headers = { "Content-Type": "application/json", "X-RapidAPI-Key": API_KEY, "X-RapidAPI-Host": "ultra-fast-webp-360-panorama-optimizer1.p.rapidapi.com", } resp = requests.post( "https://ultra-fast-webp-360-panorama-optimizer1.p.rapidapi.com/optimize", json=payload, headers=headers, ) resp.raise_for_status() data = resp.json() b64 = data["webp_base64"].split(",", 1)[-1] # strip data-URI prefix with open("output.webp", "wb") as f: f.write(base64.b64decode(b64)) print("Saved output.webp") 

Node.js (fetch, works in Next.js / Edge Functions)

const fs = require("fs"); async function optimizeImage(imageUrl) { const res = await fetch( "https://ultra-fast-webp-360-panorama-optimizer1.p.rapidapi.com/optimize", { method: "POST", headers: { "Content-Type": "application/json", "X-RapidAPI-Key": process.env.RAPIDAPI_KEY, "X-RapidAPI-Host": "ultra-fast-webp-360-panorama-optimizer1.p.rapidapi.com", }, body: JSON.stringify({ image_url: imageUrl, quality: 80, max_width: 4096 }), } ); const { webp_base64 } = await res.json(); const b64 = webp_base64.split(",")[1]; // strip data-URI prefix fs.writeFileSync("output.webp", Buffer.from(b64, "base64")); console.log("Saved output.webp"); } optimizeImage("https://example.com/panorama.jpg"); 

cURL (great for shell scripts & CI/CD)

curl -s -X POST \ "https://ultra-fast-webp-360-panorama-optimizer1.p.rapidapi.com/optimize" \ -H "Content-Type: application/json" \ -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \ -H "X-RapidAPI-Host: ultra-fast-webp-360-panorama-optimizer1.p.rapidapi.com" \ -d '{"image_url":"https://example.com/panorama.jpg","quality":80,"max_width":4096}' \ | python3 -c " import sys, json, base64 data = json.load(sys.stdin) b64 = data['webp_base64'].split(',',1)[-1] open('output.webp','wb').write(base64.b64decode(b64)) print('Saved output.webp') " 

Open-Source CLI Tool

I also published a free CLI wrapper that handles batch files:

pip install requests export RAPIDAPI_KEY=your_key_here # Single image python webp_optimizer_cli.py --url "https://example.com/panorama.jpg" # Bulk from text file python webp_optimizer_cli.py --batch-file urls.txt --quality 85 --output-dir ./out 

GitHub: github.com/socha0607-ai/bulk-360-webp-cli

Get the Free API Key

The API is live on RapidAPI with a free tier:

👉 Ultra-Fast WebP & 360 Panorama Optimizer — Free API Key

What's Next

  • Automatic AVIF fallback detection
  • Signed CDN URL support (S3, Cloudflare R2)
  • Webhook mode for async batch jobs

Questions? Drop them in the comments. Happy compressing! 🗜️