ImageOptimizerOptions
Options for the Fastly Image Optimizer, specified via the imageOptimizerOptions property
in the Request constructor. See the
Image Optimizer reference docs for
detailed documentation on all options.
1234567891011121314151617import { Format, Orient, CropMode, Region } from 'fastly:image-optimizer';
async function handleRequest(event) { return await fetch('https://www.w3.org/Graphics/PNG/text2.png', { imageOptimizerOptions: { region: Region.UsEast, format: Format.PNG, bgColor: { r: 100, g: 255, b: 9, a: 0.5 }, brightness: -20, orient: Orient.FlipVertical, crop: { size: { ratio: { width: 4, height: 3 } }, mode: CropMode.Safe }, }, backend: 'my-backend' });}
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));Properties
region
'us_east' | 'us_central' | 'us_west' | 'eu_central' | 'eu_west' | 'asia' | 'australia'View sourceSpecify the region where image optimizations should occur. This is the only required option.
Enable optimization features automatically based on browser support.
Set the background color of an image.
Set the blurriness of the output image. Number values are in the range 0.5-1000; percentage strings are also accepted.
Set the brightness of the output image (-100 to 100).
Convert an image to black and white using a given algorithm.
Increase the size of the canvas around an image.
Set the contrast of the output image (-100 to 100).
Remove pixels from an image.
Disable features that are enabled by default.
Set the ratio between physical pixels and logical pixels (1-10).
Enable features that are disabled by default.
Set how the image will fit within the size bounds provided.
format
'auto' | 'avif' | 'bjpg' | 'gif' | 'jpg' | 'jxl' | 'mp4' | 'pjpg' | 'pjxl' | 'png' | 'png8' | 'svg' | 'webp' | 'webpll' | 'webply'optionalView sourceSpecify the output format to convert the image to.
Extract the first frame from an animated image sequence.
Resize the height of the image, as integer pixels or a percentage string.
Specify the level constraints when converting to video. Must be one of:
"1.0", "1.1", "1.2", "1.3", "2.0", "2.1", "2.2", "3.0", "3.1",
"3.2", "4.0", "4.1", "4.2", "5.0", "5.1", "5.2", "6.0", "6.1",
or "6.2".
Control which metadata fields are preserved during transformation.
Automatically apply optimal quality compression.
Change the cardinal orientation of the image.
Add pixels to the edge of an image.
Remove pixels from an image before any other transformations occur.
Specify the H.264 profile class when converting to video.
Optimize the image to the given compression level for lossy file formatted images (0-100).
resizeFilter
'nearest' | 'bilinear' | 'linear' | 'bicubic' | 'cubic' | 'lanczos2' | 'lanczos3' | 'lanczos'optionalView sourceSpecify the resize filter used when resizing images.
Set the saturation of the output image (-100 to 100).
Set the sharpness of the output image.
amount:number— Sharpening amount (0-10).radius:number— Sharpening radius (0.5-1000).threshold:number— Sharpening threshold (0-255).
Remove pixels from the edge of an image.
Trim pixels from the image edges that match the specified color. Either a Color
value, or an object with color and optional threshold (0-1) properties.
Remove explicit width and height properties in SVG output.
Resize the width of the image, as integer pixels or a percentage string.