Skip to content

sametasci/go-image-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Image Proxy

A high-performance, lightweight image processing proxy server written in Go. It fetches images from remote URLs, resizes, compresses, and converts them on-the-fly using libvips (via bimg).

This project uses the Go standard library (net/http) for maximum efficiency and minimal dependencies.

Features

  • 🚀 High Performance: Powered by libvips, one of the fastest image processing libraries available.
  • 🖼 Format Conversion: Convert images to WebP, JPEG, PNG, or GIF on the fly.
  • 📏 Resizing: Smart resizing with width and height parameters.
  • 🎨 Quality Control: Adjustable compression quality for optimization.
  • 🐳 Docker Ready: Includes a multi-stage Dockerfile for small production images (Alpine based).
  • ⚙️ Configurable: Easy configuration via config.yml.

Prerequisites

If running locally (without Docker), you must have libvips installed on your system, as bimg uses C bindings.

macOS (Homebrew)

brew install vips

Linux (Ubuntu/Debian)

sudo apt-get install libvips-dev

Installation & Running

1. Local Development

Clone the repository and install dependencies:

git clone https://github.com/sametasci/go-image-proxy.git
cd go-image-proxy
go mod download

Run the server:

go run main.go

2. Using Docker (Recommended)

You can build and run the application using Docker, which handles the libvips dependency automatically.

# Build the image
docker build -t go-image-proxy .

# Run the container (mapping port 8080)
docker run -p 8080:8080 go-image-proxy

Configuration

Configuration is handled in config.yml.

Key Default Description
server.port 8080 Port the server listens on
fetch.timeout_ms 2500 Timeout in ms for fetching remote images
image.default_quality 80 Default image quality (1-100)
image.default_format webp Default output format if none specified
image.default_width 800 Fallback width if parsing fails
image.default_height 800 Fallback height if parsing fails

API Usage

Endpoint: GET /image

Query Parameters

Parameter Type Required Description
url string Yes The full URL of the source image
w int No Target width
h int No Target height
q int No Quality (1-100). Default: 80
format string No Output format (webp, jpg, png, gif)

Examples

1. Simple conversion to WebP (using defaults):

http://localhost:8080/image?url=https://example.com/image.jpg

2. Resize to 300px width and convert to JPEG:

http://localhost:8080/image?url=https://example.com/image.png&w=300&format=jpg

3. Resize to 100x100 with 90% quality:

http://localhost:8080/image?url=https://example.com/photo.jpg&w=100&h=100&q=90

License

MIT

About

High-performance Go image resizing & format conversion proxy built with bimg (libvips)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published