View a markdown version of this page

Dynamically resize photos - Dynamic Image Transformation for Amazon CloudFront

Dynamically resize photos

This solution offers the following fit options to dynamically resize an image: cover, contain, fill, inside, and outside. Refer to the sharp documentation for a description of each fit. For example:

const imageRequest = JSON.stringify({ bucket: "<myImageBucket>", key: "<myImage.jpeg>", edits: { resize: { width: 200, height: 250, fit: "cover" } } })

If you use contain as the resize fit mode, you can specify the color of the fill by providing the hex code of the color you want to use. For example:

const imageRequest = JSON.stringify({ bucket: "<myImageBucket>", key: "<myImage.jpeg>", edits: { resize: { width: 200, height: 250, fit: "contain", background: { r: 255, g: 0, b: 0, alpha: 1 } } } })