Wain is a http proxy that allows to dynamically resize and serve images from an s3 bucket.
brew install homebrew/science/vips --with-mozjpeg
docker run -v /home/user/config.yaml:/config.yaml -p 3000:3000 monder/wain /config.yaml
Wain allows to configure routes in yaml
format.
# vim: ts=2:sw=2
port: 3000
buckets:
- name: wain-demo-content
region: eu-west-1
accessKey: AKIAJMK6JWZF4F4JBSXQ
accessSecret: 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
urls:
- pattern: /images/{id:IMG_\d+}/{width:[0-9]+}{height:(x[0-9]+)?}.jpg
original:
bucket: wain-demo-content
key: original/{id}.JPG
cache:
bucket: wain-demo-content
key: cache/{id}/{width}{height}.jpg
The configuration above will process the urls only matching the pattern /images/{id:IMG_\d+}/{width:[0-9]+}{height:(x[0-9]+)?}.jpg
capturing the variables.
Note thate the height
parameter is optional (?
) and the pattern will match both:
/images/IMG_2530/100.jpg
and
/images/IMG_2530/100x150.jpg
The file will be downloaded from the bucket specified in original
. bucket
name is looked up in buckets
section. key
should be the file name inside the bucket. All variables captured in pattern
could be used here to generate the key. All unknown variables are replaced with an empty string (""
).
Requesting the file /images/IMG_2530/100.jpg
will download and resize file wain-demo-content/original/IMG_2530.JPG
to width 100px
and some height keeping the aspect ratio of the original.
Specifying the height
as well as width
will fit the original, adding a blurred background: