This is a very trim application - you give it a source (either a root directory, or a root web address), and it will allow images from this source to be resized on the fly.
It's written in rust, and relies heavily on the hyper and image crates, and in a lot of ways can be considered a simple wrapper around them.
We use the supported image formats of the image crate, with the exception of avif.
TL;DR: PNG, JPEG, GIF, BMP, ICO, TIFF, WebP, PNM, DDS, TGA, OpenEXR, farbfeld
I wanted a container I could deploy to my cluster, which could serve and dynamically resize a directory of images, and was a bit shocked I couldn't immediately find something. Not for anything important, just a website for ranking mince pies. I thought I can't be the only one with this requirement - so I'm putting this up for others to use.
As to the deeper why - it was because I wanted to send as little data as necessary over the wire, without having to statically bake sized images. I was looking at the directory of images as a datasource, rather than as images in and of themselves, due to the nature of the project.
The following environment variables are available:
IMGPRSSR_ADDRESS
: defaults to0.0.0.0
- recommend not changing this, as it binds to the container
IMGPRSSR_PORT
: defaults to3000
- the port that will be listened to
IMGPRSSR_IMAGE_SOURCE
: defaults to./images
- the root directory to source images. Can be either a folder or a
http://
/https://
web address
- the root directory to source images. Can be either a folder or a
IMGPRSSR_DEFAULT_FILTER
: defaults tonearest
- can be one of
nearest
,gaussian
,catmullrom
,lanczos3
,triangle
- can be one of
Volume-mounted Image Source:
podman run -d -v ./images:/images -p 3000:3000 ghcr.io/leemartin77/imgprssr:latest
HTTPS Image Source:
podman run -d -e IMGPRSSR_IMAGE_SOURCE=https://raw.githubusercontent.com/LeeMartin77/imgprssr/main/images -p 3000:3000 ghcr.io/leemartin77/imgprssr:latest
There is also a binary of the application included with the release, however I give no guaruntees on this working, and strongly recommend using the container.
Once the service is running, you can make a request with the following query parameters:
width
: the width of the image you want in pixelsheight
: the height of the image you want in pixelsfilter
: the filtering you want to use for resizing- one of
nearest
,gaussian
,catmullrom
,lanczos3
,triangle
- one of
Note: It's worth playing around with the filter
parameter based on the content of the image.
http://localhost:3000/test_card_sml.png?width=300
Returns: The image at /test_card_sml.png
, relative to the source, resized to 300px wide with aspect ratio preserved
http://localhost:3000/somedirectory/myimage.png?height=300
Returns: The image at /somedirectory/myimage.png
, relative to the source, resized to 300px high with aspect ratio preserved
http://localhost:3000/test_card_sml.png?width=300&height=100
Returns: The image at /test_card_sml.png
, relative to the source, resized so the longest edge is entirely in frame, and the short edge has the excess cropped. So:
Displays as:
I'm not actively looking for contributions on this since it's such a thin project, that said if there is something you need and you're willing to add it, please fork then raise a PR back to this repository - can't promise I'll merge it but I'll always be interested!
If you use this project, I'd love to hear where you used it! You can reach me a [email protected].
Test card image lifted from SVGtestcard