MCPcopy
hub / github.com/willnorris/imageproxy

github.com/willnorris/imageproxy @v0.13.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.13.0 ↗
132 symbols 417 edges 18 files 51 documented · 39%
README

imageproxy

GoDoc Test Status Test Coverage CII Best Practices

imageproxy is a caching image proxy server written in go. It features:

  • basic image adjustments like resizing, cropping, and rotation
  • access control using allowed hosts list or request signing (HMAC-SHA256)
  • support for jpeg, png, webp (decode only), tiff, and gif image formats (including animated gifs)
  • caching in-memory, on disk, or with Amazon S3, Google Cloud Storage, Azure Storage, or Redis
  • easy deployment, since it's pure go

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.

URL Structure

imageproxy URLs are of the form http://localhost/{options}/{remote_url}.

Options

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.

Remote URL

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.

Examples

The following live examples demonstrate setting different options on this source image, which measures 1024 by 678 pixels.

Options Meaning Image
200x 200px wide, proportional height 200x
x0.15 15% original height, proportional width x0.15
100x150 100 by 150 pixels, cropping as needed 100x150
100 100px square, cropping as needed 100
150,fit scale to fit 150px square, no cropping 150,fit
100,r90 100px square, rotated 90 degrees 100,r90
100,fv,fh 100px square, flipped horizontal and vertical 100,fv,fh
200x,q60 200px wide, proportional height, 60% quality 200x,q60
200x,png 200px wide, converted to PNG format 200x,png
cx175,cw400,ch300,100x crop to 400x300px starting at (175,0), scale to 100px wide cx175,cw400,ch300,100x

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 200x400,sc
150x300,sc 150x300px, smart crop 200x400

Transformation also works on animated gifs. Here is this source image resized to 200px square and rotated 270 degrees:

200,r270

Getting Started

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.

Cache

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:

  • "endpoint" - specify an alternate API endpoint
  • "disableSSL" - set to "1" to disable SSL when calling the API
  • "s3ForcePathStyle" - set to "1" to force the request to use path-style addressing

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 URL (e.g. gcs://bucket-name/optional-path-prefix) - will cache images on Google Cloud Storage. Authentication is documented in Google's Application Default Credentials docs.
  • azure URL (e.g. azure://container-name/) - will cache images on Azure Storage. This requires AZURESTORAGE_ACCOUNT_NAME and AZURESTORAGE_ACCESS_KEY environment variables to bet set.
  • redis URL (e.g. 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

Extension points exported contracts — how you extend this code

Cache (Interface)
The Cache interface defines a cache for storing arbitrary data. The interface is designed to align with httpcache.Cache [3 …
cache.go

Core symbols most depended-on inside this repo

Get
called by 18
cache.go
String
called by 17
data.go
String
called by 16
cmd/imageproxy/main.go
Set
called by 15
cache.go
Header
called by 9
third_party/http/server.go
Transform
called by 8
transform.go
evaluateFloat
called by 8
transform.go
logf
called by 8
imageproxy.go

Shape

Function 77
Method 39
Struct 13
TypeAlias 2
Interface 1

Languages

Go100%

Modules by API surface

imageproxy_test.go18 symbols
imageproxy.go17 symbols
cmd/imageproxy/main.go11 symbols
transform_test.go10 symbols
data.go10 symbols
third_party/http/server.go9 symbols
caddy/module.go8 symbols
cache.go8 symbols
transform.go7 symbols
internal/gcscache/gcscache.go7 symbols
internal/s3cache/s3cache.go6 symbols
cmd/imageproxy-sign/main_test.go6 symbols

Dependencies from manifests, versioned

cel.dev/exprv0.19.2 · 1×
cloud.google.com/gov0.120.0 · 1×
cloud.google.com/go/authv0.16.0 · 1×
cloud.google.com/go/auth/oauth2adaptv0.2.8 · 1×
cloud.google.com/go/compute/metadatav0.6.0 · 1×
cloud.google.com/go/monitoringv1.24.0 · 1×
cloud.google.com/go/storagev1.52.0 · 1×
filippo.io/edwards25519v1.1.0 · 1×
github.com/AndreasBriese/bbloomv0.0.0-2019082515265 · 1×
github.com/Azure/azure-sdk-for-gov68.0.0+incompatible · 1×
github.com/Azure/go-autorestv14.2.0+incompatible · 1×

For agents

$ claude mcp add imageproxy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact