mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
README.md: format file
I'm honestly not sure which formatter this is using. Probably something from the markdown LSP server I'm using. Maybe something built in to neovim or that ships with LazyVim?
This commit is contained in:
parent
84960fc8a0
commit
9708b430f5
1 changed files with 119 additions and 118 deletions
107
README.md
107
README.md
|
@ -7,13 +7,13 @@
|
|||
|
||||
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
|
||||
- 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
|
||||
- caching in-memory, on disk, or with Amazon S3, Google Cloud Storage, Azure
|
||||
Storage, or Redis
|
||||
- easy deployment, since it's pure go
|
||||
- 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
|
||||
|
@ -29,11 +29,11 @@ You can see the go versions that are tested against in [.github/workflows/tests.
|
|||
[most recent major go releases]: https://golang.org/doc/devel/release.html
|
||||
[.github/workflows/tests.yml]: ./.github/workflows/tests.yml
|
||||
|
||||
## URL Structure ##
|
||||
## URL Structure
|
||||
|
||||
imageproxy URLs are of the form `http://localhost/{options}/{remote_url}`.
|
||||
|
||||
### Options ###
|
||||
### Options
|
||||
|
||||
Options are available for cropping, resizing, rotation, flipping, and digital
|
||||
signatures among a few others. Options for are specified as a comma delimited
|
||||
|
@ -43,7 +43,7 @@ overwrite previous values.
|
|||
See the full list of available options at
|
||||
<https://godoc.org/willnorris.com/go/imageproxy#ParseOptions>.
|
||||
|
||||
### Remote URL ###
|
||||
### Remote URL
|
||||
|
||||
The URL of the original image to load is specified as the remainder of the
|
||||
path, without any encoding. For example,
|
||||
|
@ -54,34 +54,34 @@ strings.
|
|||
|
||||
[optimize caching]: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
|
||||
|
||||
### Examples ###
|
||||
### Examples
|
||||
|
||||
The following live examples demonstrate setting different options on [this
|
||||
source image][small-things], which measures 1024 by 678 pixels.
|
||||
|
||||
[small-things]: https://willnorris.com/images/imageproxy/small-things.jpg
|
||||
|
||||
Options | Meaning | Image
|
||||
--------|------------------------------------------|------
|
||||
200x | 200px wide, proportional height | <a href="https://willnorris.com/api/imageproxy/200x/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/200x/https://willnorris.com/images/imageproxy/small-things.jpg" alt="200x"></a>
|
||||
x0.15 | 15% original height, proportional width | <a href="https://willnorris.com/api/imageproxy/x0.15/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/x0.15/https://willnorris.com/images/imageproxy/small-things.jpg" alt="x0.15"></a>
|
||||
100x150 | 100 by 150 pixels, cropping as needed | <a href="https://willnorris.com/api/imageproxy/100x150/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100x150/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100x150"></a>
|
||||
100 | 100px square, cropping as needed | <a href="https://willnorris.com/api/imageproxy/100/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100"></a>
|
||||
150,fit | scale to fit 150px square, no cropping | <a href="https://willnorris.com/api/imageproxy/150,fit/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/150,fit/https://willnorris.com/images/imageproxy/small-things.jpg" alt="150,fit"></a>
|
||||
100,r90 | 100px square, rotated 90 degrees | <a href="https://willnorris.com/api/imageproxy/100,r90/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100,r90/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100,r90"></a>
|
||||
100,fv,fh | 100px square, flipped horizontal and vertical | <a href="https://willnorris.com/api/imageproxy/100,fv,fh/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100,fv,fh/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100,fv,fh"></a>
|
||||
200x,q60 | 200px wide, proportional height, 60% quality | <a href="https://willnorris.com/api/imageproxy/200x,q60/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/200x,q60/https://willnorris.com/images/imageproxy/small-things.jpg" alt="200x,q60"></a>
|
||||
200x,png | 200px wide, converted to PNG format | <a href="https://willnorris.com/api/imageproxy/200x,png/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/200x,png/https://willnorris.com/images/imageproxy/small-things.jpg" alt="200x,png"></a>
|
||||
cx175,cw400,ch300,100x | crop to 400x300px starting at (175,0), scale to 100px wide | <a href="https://willnorris.com/api/imageproxy/cx175,cw400,ch300,100x/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/cx175,cw400,ch300,100x/https://willnorris.com/images/imageproxy/small-things.jpg" alt="cx175,cw400,ch300,100x"></a>
|
||||
| Options | Meaning | Image |
|
||||
| ---------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 200x | 200px wide, proportional height | <a href="https://willnorris.com/api/imageproxy/200x/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/200x/https://willnorris.com/images/imageproxy/small-things.jpg" alt="200x"></a> |
|
||||
| x0.15 | 15% original height, proportional width | <a href="https://willnorris.com/api/imageproxy/x0.15/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/x0.15/https://willnorris.com/images/imageproxy/small-things.jpg" alt="x0.15"></a> |
|
||||
| 100x150 | 100 by 150 pixels, cropping as needed | <a href="https://willnorris.com/api/imageproxy/100x150/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100x150/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100x150"></a> |
|
||||
| 100 | 100px square, cropping as needed | <a href="https://willnorris.com/api/imageproxy/100/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100"></a> |
|
||||
| 150,fit | scale to fit 150px square, no cropping | <a href="https://willnorris.com/api/imageproxy/150,fit/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/150,fit/https://willnorris.com/images/imageproxy/small-things.jpg" alt="150,fit"></a> |
|
||||
| 100,r90 | 100px square, rotated 90 degrees | <a href="https://willnorris.com/api/imageproxy/100,r90/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100,r90/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100,r90"></a> |
|
||||
| 100,fv,fh | 100px square, flipped horizontal and vertical | <a href="https://willnorris.com/api/imageproxy/100,fv,fh/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/100,fv,fh/https://willnorris.com/images/imageproxy/small-things.jpg" alt="100,fv,fh"></a> |
|
||||
| 200x,q60 | 200px wide, proportional height, 60% quality | <a href="https://willnorris.com/api/imageproxy/200x,q60/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/200x,q60/https://willnorris.com/images/imageproxy/small-things.jpg" alt="200x,q60"></a> |
|
||||
| 200x,png | 200px wide, converted to PNG format | <a href="https://willnorris.com/api/imageproxy/200x,png/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/200x,png/https://willnorris.com/images/imageproxy/small-things.jpg" alt="200x,png"></a> |
|
||||
| cx175,cw400,ch300,100x | crop to 400x300px starting at (175,0), scale to 100px wide | <a href="https://willnorris.com/api/imageproxy/cx175,cw400,ch300,100x/https://willnorris.com/images/imageproxy/small-things.jpg"><img src="https://willnorris.com/api/imageproxy/cx175,cw400,ch300,100x/https://willnorris.com/images/imageproxy/small-things.jpg" alt="cx175,cw400,ch300,100x"></a> |
|
||||
|
||||
The [smart crop feature](https://godoc.org/willnorris.com/go/imageproxy#hdr-Smart_Crop)
|
||||
can best be seen by comparing crops of [this source image][judah-sheets], with
|
||||
and without smart crop enabled.
|
||||
|
||||
Options | Meaning | Image
|
||||
--------|------------------------------------------|------
|
||||
150x300 | 150x300px, standard crop | <a href="https://willnorris.com/api/imageproxy/150x300/https://judahnorris.com/images/judah-sheets.jpg"><img src="https://willnorris.com/api/imageproxy/150x300/https://judahnorris.com/images/judah-sheets.jpg" alt="200x400,sc"></a>
|
||||
150x300,sc | 150x300px, smart crop | <a href="https://willnorris.com/api/imageproxy/150x300,sc/https://judahnorris.com/images/judah-sheets.jpg"><img src="https://willnorris.com/api/imageproxy/150x300,sc/https://judahnorris.com/images/judah-sheets.jpg" alt="200x400"></a>
|
||||
| Options | Meaning | Image |
|
||||
| ---------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 150x300 | 150x300px, standard crop | <a href="https://willnorris.com/api/imageproxy/150x300/https://judahnorris.com/images/judah-sheets.jpg"><img src="https://willnorris.com/api/imageproxy/150x300/https://judahnorris.com/images/judah-sheets.jpg" alt="200x400,sc"></a> |
|
||||
| 150x300,sc | 150x300px, smart crop | <a href="https://willnorris.com/api/imageproxy/150x300,sc/https://judahnorris.com/images/judah-sheets.jpg"><img src="https://willnorris.com/api/imageproxy/150x300,sc/https://judahnorris.com/images/judah-sheets.jpg" alt="200x400"></a> |
|
||||
|
||||
[judah-sheets]: https://judahnorris.com/images/judah-sheets.jpg
|
||||
|
||||
|
@ -92,7 +92,7 @@ image][material-animation] resized to 200px square and rotated 270 degrees:
|
|||
|
||||
<a href="https://willnorris.com/api/imageproxy/200,r270/https://willnorris.com/images/imageproxy/material-animations.gif"><img src="https://willnorris.com/api/imageproxy/200,r270/https://willnorris.com/images/imageproxy/material-animations.gif" alt="200,r270"></a>
|
||||
|
||||
## Getting Started ##
|
||||
## Getting Started
|
||||
|
||||
Install the package using:
|
||||
|
||||
|
@ -108,20 +108,20 @@ 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 ###
|
||||
### 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
|
||||
- `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
|
||||
- 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
|
||||
- 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
|
||||
|
@ -131,6 +131,7 @@ enabled using the `-cache` flag. It supports the following values:
|
|||
Additional configuration options ([further documented here][aws-options])
|
||||
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
|
||||
|
@ -147,14 +148,14 @@ enabled using the `-cache` flag. It supports the following values:
|
|||
|
||||
[aws-options]: https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
|
||||
|
||||
- gcs URL (e.g. `gcs://bucket-name/optional-path-prefix`) - will cache images
|
||||
- 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](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application).
|
||||
- azure URL (e.g. `azure://container-name/`) - will cache images on
|
||||
- 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
|
||||
- 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](https://www.iana.org/assignments/uri-schemes/prov/redis).
|
||||
Rather than specify password in the URI, use the `REDIS_PASSWORD`
|
||||
|
@ -181,7 +182,7 @@ first check an in-memory cache for an image, followed by a gcs bucket:
|
|||
|
||||
[tiered fashion]: https://godoc.org/github.com/die-net/lrucache/twotier
|
||||
|
||||
### Allowed Referrer List ###
|
||||
### Allowed Referrer List
|
||||
|
||||
You can limit images to only be accessible for certain hosts in the HTTP
|
||||
referrer header, which can help prevent others from hotlinking to images. It can
|
||||
|
@ -189,12 +190,11 @@ be enabled by running:
|
|||
|
||||
imageproxy -referrers example.com
|
||||
|
||||
|
||||
Reload the [codercat URL][], and you should now get an error message. You can
|
||||
specify multiple hosts as a comma separated list, or prefix a host value with
|
||||
`*.` to allow all sub-domains as well.
|
||||
|
||||
### Allowed and Denied Hosts List ###
|
||||
### Allowed and Denied Hosts List
|
||||
|
||||
You can limit the remote hosts that the proxy will fetch images from using the
|
||||
`allowHosts` and `denyHosts` flags. This is useful, for example, for locking
|
||||
|
@ -219,7 +219,7 @@ blocking reserved ranges like `127.0.0.0/8`, `192.168.0.0/16`, etc.
|
|||
|
||||
If a host matches both an allowed and denied host, the request will be denied.
|
||||
|
||||
### Allowed Content-Type List ###
|
||||
### Allowed Content-Type List
|
||||
|
||||
You can limit what content types can be proxied by using the `contentTypes`
|
||||
flag. By default, this is set to `image/*`, meaning that imageproxy will
|
||||
|
@ -227,7 +227,7 @@ process any image types. You can specify multiple content types as a comma
|
|||
separated list, and suffix values with `*` to perform a wildcard match. Set the
|
||||
flag to an empty string to proxy all requests, regardless of content type.
|
||||
|
||||
### Signed Requests ###
|
||||
### Signed Requests
|
||||
|
||||
Instead of an allowed host list, you can require that requests be signed. This
|
||||
is useful in preventing abuse when you don't have just a static list of hosts
|
||||
|
@ -262,7 +262,7 @@ If both a whiltelist and signatureKey are specified, requests can match either.
|
|||
In other words, requests that match one of the allowed hosts don't necessarily
|
||||
need to be signed, though they can be.
|
||||
|
||||
### Default Base URL ###
|
||||
### Default Base URL
|
||||
|
||||
Typically, remote images to be proxied are specified as absolute URLs.
|
||||
However, if you commonly proxy images from a single source, you can provide a
|
||||
|
@ -277,14 +277,14 @@ effective method to mask the true source of the images being proxied; it is
|
|||
trivial to discover the base URL being used. Even when a base URL is
|
||||
specified, you can always provide the absolute URL of the image to be proxied.
|
||||
|
||||
### Scaling beyond original size ###
|
||||
### Scaling beyond original size
|
||||
|
||||
By default, the imageproxy won't scale images beyond their original size.
|
||||
However, you can use the `scaleUp` command-line flag to allow this to happen:
|
||||
|
||||
imageproxy -scaleUp true
|
||||
|
||||
### WebP and TIFF support ###
|
||||
### WebP and TIFF support
|
||||
|
||||
Imageproxy can proxy remote webp images, but they will be served in either jpeg
|
||||
or png format (this is because the golang webp library only supports webp
|
||||
|
@ -298,49 +298,49 @@ default if any transformation is requested. To force encoding as tiff, pass the
|
|||
"tiff" option. Like webp, tiff images will be served as-is without any format
|
||||
conversion if no transformation is requested.
|
||||
|
||||
|
||||
Run `imageproxy -help` for a complete list of flags the command accepts. If
|
||||
you want to use a different caching implementation, it's probably easiest to
|
||||
just make a copy of `cmd/imageproxy/main.go` and customize it to fit your
|
||||
needs... it's a very simple command.
|
||||
|
||||
### Environment Variables ###
|
||||
### Environment Variables
|
||||
|
||||
All configuration flags have equivalent environment variables of the form
|
||||
`IMAGEPROXY_$NAME`. For example, an on-disk cache could be configured by calling
|
||||
|
||||
IMAGEPROXY_CACHE="/tmp/imageproxy" imageproxy
|
||||
|
||||
## Deploying ##
|
||||
## Deploying
|
||||
|
||||
In most cases, you can follow the normal procedure for building a deploying any
|
||||
go application. For example:
|
||||
|
||||
- `go build willnorris.com/go/imageproxy/cmd/imageproxy`
|
||||
- copy resulting binary to `/usr/local/bin`
|
||||
- copy [`etc/imageproxy.service`](etc/imageproxy.service) to
|
||||
- `go build willnorris.com/go/imageproxy/cmd/imageproxy`
|
||||
- copy resulting binary to `/usr/local/bin`
|
||||
- copy [`etc/imageproxy.service`](etc/imageproxy.service) to
|
||||
`/lib/systemd/system` and enable using `systemctl`.
|
||||
|
||||
Instructions have been contributed below for running on other platforms, but I
|
||||
don't have much experience with them personally.
|
||||
|
||||
### Heroku ###
|
||||
### Heroku
|
||||
|
||||
It's easy to vendorize the dependencies with `Godep` and deploy to Heroku. Take
|
||||
a look at [this GitHub repo](https://github.com/oreillymedia/prototype-imageproxy/tree/heroku)
|
||||
(make sure you use the `heroku` branch).
|
||||
|
||||
### AWS Elastic Beanstalk ###
|
||||
### AWS Elastic Beanstalk
|
||||
|
||||
[O’Reilly Media](https://github.com/oreillymedia) set up [a repository](https://github.com/oreillymedia/prototype-imageproxy)
|
||||
with everything you need to deploy imageproxy to Elastic Beanstalk. Just follow the instructions
|
||||
in the [README](https://github.com/oreillymedia/prototype-imageproxy/blob/master/Readme.md).
|
||||
|
||||
### Docker ###
|
||||
### Docker
|
||||
|
||||
A docker image is available at [`ghcr.io/willnorris/imageproxy`](https://github.com/willnorris/imageproxy/pkgs/container/imageproxy).
|
||||
|
||||
You can run it by
|
||||
|
||||
```
|
||||
docker run -p 8080:8080 ghcr.io/willnorris/imageproxy -addr 0.0.0.0:8080
|
||||
```
|
||||
|
@ -360,7 +360,7 @@ Note that all configuration options can be set using [environment
|
|||
variables](#environment-variables), which is often the preferred approach for
|
||||
containers.
|
||||
|
||||
### nginx ###
|
||||
### nginx
|
||||
|
||||
Use the `proxy_pass` directive to send requests to your imageproxy instance.
|
||||
For example, to run imageproxy at the path "/api/imageproxy/", set:
|
||||
|
@ -380,10 +380,11 @@ to alter the precedence order by setting:
|
|||
}
|
||||
```
|
||||
|
||||
## Clients ##
|
||||
## Clients
|
||||
|
||||
- [Ruby](https://github.com/azolf/imageproxy_ruby)
|
||||
|
||||
## License ##
|
||||
## License
|
||||
|
||||
imageproxy is copyright its respective authors. All of my personal work on
|
||||
imageproxy through 2020 (which accounts for the majority of the code) is
|
||||
|
|
Loading…
Reference in a new issue