imageproxy is a caching image proxy server written in go. It features:
Personally, I use it primarily to dynamically resize images hosted on my own site (read more in this post). But you can also enable request signing and use it as an SSL proxy for remote images, similar to atmos/camo but with additional image adjustment options.
I aim to keep imageproxy compatible with the two most recent major go releases. I also keep track of the minimum go version that still works (currently go1.18), but that might change at any time. You can see the go versions that are tested against in .github/workflows/tests.yml.
imageproxy URLs are of the form http://localhost/{options}/{remote_url}.
Options are available for cropping, resizing, rotation, flipping, and digital signatures among a few others. Options for are specified as a comma delimited list of parameters, which can be supplied in any order. Duplicate parameters overwrite previous values.
See the full list of available options at https://pkg.go.dev/willnorris.com/go/imageproxy#ParseOptions.
The URL of the original image to load is specified as the remainder of the path. It may be included in plain text without any encoding, percent-encoded (aka URL encoded), or base64 encoded (URL safe, no padding).
When no encoding is used, any URL query string is treated as part of the remote URL.
For example, given the proxy URL of http://localhost/x/http://example.com/?id=1,
the remote URL is http://example.com/?id=1.
When percent-encoding is used, the full URL must be encoded.
Any query string on the proxy URL is NOT included as part of the remote URL.
Percent-encoded URLs must be absolute URLs;
they cannot be relative URLs used with a default base URL.
For example, http://localhost/x/http%3A%2F%2Fexample.com%2F%3Fid%3D1.
When base64 encoding is used, the full URL must be encoded.
Any query string on the proxy URL is NOT included as part of the remote URL.
Base64 encoded URLs may be relative URLs used with a default base URL.
For example, http://localhost/x/aHR0cDovL2V4YW1wbGUuY29tLz9pZD0x.
The following live examples demonstrate setting different options on this source image, which measures 1024 by 678 pixels.
The smart crop feature can best be seen by comparing crops of this source image, with and without smart crop enabled.
| Options | Meaning | Image |
|---|---|---|
| 150x300 | 150x300px, standard crop | ![]() |
| 150x300,sc | 150x300px, smart crop | ![]() |
Transformation also works on animated gifs. Here is this source image resized to 200px square and rotated 270 degrees:
Install the package using:
go install willnorris.com/go/imageproxy/cmd/imageproxy@latest
Once installed, ensure $GOPATH/bin is in your $PATH, then run the proxy
using:
imageproxy
This will start the proxy on port 8080, without any caching and with no allowed host list (meaning any remote URL can be proxied). Test this by navigating to http://localhost:8080/500/https://octodex.github.com/images/codercat.jpg and you should see a 500px square coder octocat.
By default, the imageproxy command does not cache responses, but caching can be
enabled using the -cache flag. It supports the following values:
memory - uses an in-memory LRU cache. By default, this is limited to
100mb. To customize the size of the cache or the max age for cached items,
use the format memory:size:age where size is measured in mb and age is a
duration. For example, memory:200:4h will create a 200mb cache that will
cache items no longer than 4 hours.directory on local disk (e.g. /tmp/imageproxy) - will cache images
on disk
s3 URL (e.g. s3://region/bucket-name/optional-path-prefix) - will cache
images on Amazon S3. This requires either an IAM role and instance profile
with access to your your bucket or AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
environmental variables be set. (Additional methods of loading credentials
are documented in the aws-sdk-go session
package).
Additional configuration options (further documented here) may be specified as URL query string parameters, which are mostly useful when working with s3-compatible services:
For example, when working with minio, which doesn't use regions, provide a dummy region value and custom endpoint value:
s3://fake-region/bucket/folder?endpoint=minio:9000&disableSSL=1&s3ForcePathStyle=1
Similarly, for Digital Ocean Spaces, provide a dummy region value and the appropriate endpoint for your space:
s3://fake-region/bucket/folder?endpoint=sfo2.digitaloceanspaces.com
gcs://bucket-name/optional-path-prefix) - will cache images
on Google Cloud Storage. Authentication is documented in Google's
Application Default Credentials
docs.azure://container-name/) - will cache images on
Azure Storage. This requires AZURESTORAGE_ACCOUNT_NAME and
AZURESTORAGE_ACCESS_KEY environment variables to bet set.redis://hostname/) - will cache images on
the specified redis host. The full URL syntax is defined by the redis URI
registration.
Rather than specify password in the URI, use the REDIS_PASSWORD
environment variable.For example, to cache files on disk in the /tmp/imageproxy directory:
imageproxy -cache /tmp/imageproxy
Reload the codercat URL, and then inspect the contents of
/tmp/imageproxy. Within the subdirectories, there should be two files, one
for the original full-size codercat image, and one for the resized 500px
version.
Multiple caches can be specified by separating them by spaces or by repeating
the -cache flag multiple times. The caches will be created in a [tiered
fashion][]. Typically this is used to put a smaller and faster in-m
$ claude mcp add imageproxy \
-- python -m otcore.mcp_server <graph>