A reworked version of Tachyon that works with Lambda@Edge
Tachyon@Edge is a fork of Tachyon and built with some strong opinions and assumptions:
Tachyon works best with WordPress, coupled with S3 Uploads and the Tachyon Plugin.
Tachyon provides a simple HTTP interface in the form of:
https://{tachyon-domain}/my/image/path/on/s3.png?w=100&h=80
It's really that simple!
Requests that aren't images (gif, jpg, png, webp) get passed through to the S3 bucket for CloudFront to serve as is. Images can be processed via query strings.
URL Arg | Type | Description |
---|---|---|
w |
Number | Max width of the image. |
h |
Number | Max height of the image. |
resize fit |
String, "w,h" | Resize and crop an image to exact width,height pixel dimensions. |
quality |
Number, 0-100 | Image quality (JPG and WEBP only). |
crop |
String, "x,y,w,h" | Crop an image by percentages x-offset,y-offset,width,height (x,y,w,h). Percentages are used so that you don’t need to recalculate the cropping when transforming the image in other ways such as resizing it. crop=160px,160px,788px,788px takes a 788 by 788 square starting at 160 by 160. |
webp |
Boolean, 1 | Force WebP format. |
lb |
String, "w,h" | Add letterboxing effect to images, by scaling them to width, height while maintaining the aspect ratio and filling the rest with black or background . |
background |
String | Add background color via name (red) or hex value (%23ff0000). Don't forget to escape # as %23 . |
negative |
Boolean, 1 | Reverse the colors of the image. |
flip |
Boolean, 1 | Flip the image vertically. |
flop |
Boolean, 1 | Flip the image horizontally. |
rotate |
0, 90, 180, 270 | Rotate the image a certain number of degrees. |
grayscale greyscale |
Boolean, 1 | Convert the image to grayscale |
For more details checkout the docs.
/resized/
)rotate
, grayscale
, negative
)config.json
with your own region and bucket valuesCloudWatchLogsFullAccess
, AWSLambdaExecute
, and CloudFrontReadOnlyAccess
policies to the roleNode.js 6.10
Upload a File from Amazon S3
S3 link URL
fieldlambda-handler.handler
256 MB
and timeout to 30 sec
Publish New Version
arn:aws:lambda:us-east-1:000000000000:function:your-function-name
), you will need it laterRedirect HTTP to HTTPS
GET, HEAD
None (Improves Caching)
Forward all, cache based on all
No
No
Origin Request
None
Default CloudFront Certificate (*.cloudfront.net)
HTTP/2, HTTP/1.1, HTTP/1.0
Enabled
Create Distribution
button and wait?w=100&h=80
appended* You need to add the version number of the Lambda function to the end of the ARN like arn:aws:lambda:us-east-1:000000000000:function:your-function-name:1
for version 1 of the Lambda function. Every time you publish a new version you need to edit your CloudFront distribution and change this value.
To work with the Tachyon@Edge locally you need to perform the following steps:
libvips
on macOS: brew install homebrew/science/vips --with-webp --with-graphicsmagick
[email protected]:spiritedmedia/tachyon-edge.git
npm install
local-config.json
with the AWS S3 credentials, region, and bucket name you want to use, in the following format:{
"accessKeyId": "***",
"secretAccessKey": "****",
"region": "us-east-1",
"bucket": "my-bucket-name"
}
node server.js [port]
A docker file is included for building the node_modules
for the AWS Lambda function. Follow these steps:
npm run-script build-docker
to build the docker image (you only need to do this once)npm run-script build-node-modules
to compile the node modules for an Ubuntu Linux environmentconfig.json
to specify which S3 bucket you want the Lambda function to usenpm run-script build-zip
to build a zip file called lambda.zip
lambda.zip
to a bucket on S3Props to Human Made for the original Tachyon project written and maintained by Joe Hoyle.
Tachyon is inspired by Photon by Automattic. As Tachyon is not an all-purpose image resizer, rather it uses a media library in Amazon S3, it has a different use case to Photon.
Tachyon uses the Sharp (Used under the license Apache License 2.0) Node.js library for the resizing operations, which in turn uses the great libvips library.