This server can read pictures in png (first priority) and jpg (second priority) format from disk and serve them over http as png or jpg images at the resolution requested by the client. It can also serve raw (unmodified) versions of png, jpg, svg and pdf files.
/heightp/path/to/image.{jpg,png}
/widthw/path/to/image.{jpg,png}
/raw/path/to/image.ext (where ext can be one of png, jpg, svg, pdf)
Configuration is done exclusively using environment variables. The following variables are supported:
pwd when you execute the server.The server does not do any internal caching and reads and scales the image on each request for which a body has to be sent.
This server sends Last-Modified and Cache-Control: "public, max-age=MAX_AGE headers in responses.
304 Not Modified responses are sent when a correct If-Modified-Since request header is present.
As Last-Modified time the time of the the first matching source image is used.
This results in the Browser Cache being used when directly accessing the server.
When configuring nginx as reverse proxy as shown in docker-compose.yaml and nginx/default.conf, this results in a very high performance system. nginx uses up to 4GB of disk space as a cache and only checks every 15s with the imgsrv if the file was modified. The actual image is only scaled once after startup unless the nginx cache overflows.
The serve can be used standalone with the following limitations:
For production, a reverse proxy should be added for caching and possibly for ssl or http2 termination. See docker-compose.yaml for an example setup using nginx.
For development on this server, you might want to use gin, which automatically recompiles the server on each request if the source has changed.
go get github.com/codegangsta/gin
export IMAGE_DIR=/home/lk/tmp/pics_raw/
gin
To build the docker images use:
docker-compose build
Content type
Image
Digest
Size
2.1 MB
Last updated
over 5 years ago
docker pull koestler/go-image-server