Projects / Software · Active

mod_dims

The Apache httpd module that resizes, crops, and converts images on request.

Language
C
Runs in
Apache httpd
Images
ImageMagick 7
License
Apache 2.0

Overview

mod_dims runs inside Apache httpd. A request such as /dims5/resize/100x100/?url=https://example.com/cat.jpg fetches the image, resizes it to fit 100 by 100, and returns it. It caches nothing, so a site keeps one original and serves as many variants as it needs.

The image work uses ImageMagick 7 through MagickWand. Images come in over libcurl, and an allowlist controls which hosts they can come from.

/dims5/ signs every parameter that changes the result with HMAC-SHA256. The older /dims4/ and /dims3/ endpoints are still supported. go-dims is a newer server in Go that reads the same URLs.

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.

Server
Commands, applied from left to right
    Quick preview. Load libvips (about 5 MB) for the real result.

    Sample photo by Adhitya Andanu on Pexels.

    Run it

    Start the container with a signing key for /dims5/:

    docker run -p 8000:8000 -e DIMS_SIGNING_KEY=a-long-random-string \
      ghcr.io/beetlebugorg/mod_dims:latest
    

    To add mod_dims to your own httpd, build it with CMake. See Installation.

    Build it from source

    You need httpd with apxs, APR, libcurl, OpenSSL, and ImageMagick 7.

    cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo
    cmake --build build
    

    The tests run in a container against a test origin: make -C test test.

    Licenses and credits

    mod_dims is Copyright 2009 AOL LLC, under the Apache License 2.0.

    The sample photo is by Adhitya Andanu on Pexels.