A simple, lightweight image processing and compression server built with Go and Fiber. This server provides both HTTP and WebSocket APIs to queue and process image compression tasks, supporting WebP, PNG, and JPEG formats.
bimg (a Go wrapper for libvips) and pngquant for high-quality, efficient compression.config.yaml file.The easiest way to deploy this server is by using the provided Dockerfile and Docker Compose.
Clone the Repository
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
Configure the Server
Edit the config.yaml file to set your desired options.
server.port: The port the server will listen on.server.output_dir: The directory to save processed images.upload.max_upload_size: The maximum file size for uploads (e.g., 10MB, 500KB).upload.max_concurrent_tasks: The number of concurrent image processing workers.upload.max_age: The maximum number of hours an uploaded image is kept before being automatically deleted.# config.yaml example
server:
port: 8080
output_dir: "output"
upload:
max_upload_size: 10MB
max_concurrent_tasks: 3
max_age: 24
download:
download_url: "download/"
Build and Run with Docker Compose
Create a docker-compose.yaml file in the project root with the following content:
version: '3.8'
services:
tinyimage-server:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
volumes:
- ./config.yaml:/config/config.yaml
- ./output:/output
Then, run the following command to build and start the server:
docker-compose up --build -d
Or with prebuilt image ghcr.io/humanutopia/tinyimage-server:latest
version: '3.8'
services:
tinyimage-server:
image: ghcr.io/humanutopia/tinyimage-server
container_name: tinyimage-server
ports:
- "8080:8080"
volumes:
- ./config.yaml:/config/config.yaml
- ./output:/app/output
docker-compose up -d
The server will now be running at http://localhost:8080.
The server provides a RESTful API and a WebSocket API.
GET / - Server StatusDescription: Get server configuration and version info. Example:
curl http://localhost:8080/
Response:
{
"version": "v0.0.1",
"download_url": "download/",
"max_upload_size_bytes": "10MB",
"max_concurrent_tasks": 3,
"max_age": 24
}
POST /upload - Upload ImageDescription: Upload an image for processing. The server queues the task and returns a unique MD5 hash.
Request: multipart/form-data
picture: (file, required) The image file.format: (string, optional) Output format (webp, png, jpg). Default is webp.quality: (int, optional) For jpg format, 1-100. Default is 80.Example:
curl -X POST http://localhost:8080/upload \
-F "picture=@/path/to/your/image.jpg" \
-F "format=png"
Response:
{
"message": "Your image is queued for processing",
"md5": "a1b2c3d4e5f6...",
"format": "png",
"quality": 0
}
Error:
{"message": "Image already processed for this format/quality",
"md5": "213d21f...",
"format": "png",
"quality": 80
}
GET /status/:md5 - Check Task StatusDescription: Check the processing status of an image. Example:
curl http://localhost:8080/status/a1b2c3d4e5f6...
Response:
[
{
"md5": "a1b2c3d4e5f6...",
"status": "processing",
"format": "png",
"quality": 0
}
]
GET /download/:md5 - Download Processed ImageDescription: Download the processed image file. Example:
curl -o processed_image.png http://localhost:8080/download/a1b2c3d4e5f6...
Response: The raw image file.
The WebSocket API allows for real-time communication, providing instant feedback and the processed image file directly over the connection.
ws://localhost:8080/wsClient to Server (Request): Send a JSON object containing the Base64-encoded image data.
{
"filename": "my_image.jpeg",
"format": "jpg",
"data": "iVBORw0KGgo...",
"quality": 80
}
Server to Client (Response):
The server will send messages with status updates. When the image is processed, a done message with the Base64-encoded output file is sent.
{"status": "queued", "md5": "a1b2c3d4...", "format": "jpg", "quality": 80}
{"status": "processing", "md5": "a1b2c3d4...", "format": "jpg", "quality": 80}
{
"status": "done",
"md5": "a1b2c3d4...",
"format": "jpg",
"quality": 80,
"file": "iVBORw0KGgo..."
}
{"status": "error", "message": "invalid_json"}
{"status": "error", "message": "unsupported_format"}
{"status": "size_exceeded", "message": "file too large"}
{"status": "unsupported_format", "message": "only webp/png/jpg supported"}
Content type
Image
Digest
sha256:246da18ea…
Size
76.9 MB
Last updated
4 months ago
docker pull ericthedev/tinyimage-server