Projects / Software · Active
go-dims
An image server in Go that resizes, crops, and converts images from the URL.
- Language
- Go + libvips
- Runs as
- Binary, Docker, Lambda
- Signing
- HMAC-SHA256
- License
- MIT
Overview
A site keeps one original of each image. go-dims makes each size and format when a page asks for it. You write the variant in the URL, for example /v5/thumbnail/200x200/?url=cat.jpg, and go-dims fetches the image, applies the commands from left to right, and returns the result.
The image work uses libvips. The server is one static binary. The Docker image starts from scratch, so it has no shell and no package manager.
go-dims reads the same URLs as mod_dims, the Apache module it replaces. A site can move from one to the other with no change to its pages.
Live demo
Build a DIMS URL
Add commands to the chain. The page writes the URL and signs it with your key. It also shows a preview of the result. Nothing goes to a server.
Sample photo by Adhitya Andanu on Pexels.
Run it
Start the server in development mode. Development mode accepts unsigned requests:
docker run -e DIMS_DEVELOPMENT_MODE=true -e DIMS_SIGNING_KEY=devmode \
-p 8080:8080 ghcr.io/beetlebugorg/go-dims serve
Then open http://127.0.0.1:8080/v5/resize/100x100/?url=https://images.pexels.com/photos/1539116/pexels-photo-1539116.jpeg in a browser.
To install the dims command on macOS or Linux, run brew install beetlebugorg/tap/go-dims.
Sign a URL
In production, each request must have a sig parameter. The signature is the HMAC-SHA256 of three lines: the command path, the image URL, and the other query parameters in sorted order.
dims sign --key-file=signing-key.txt \
"http://localhost:8080/v5/resize/200x200/?url=cat.jpg"
The URL builder above makes the same signature in your browser.
Licenses and credits
The sample photo is by Adhitya Andanu on Pexels.