imageOptimizerOptions
Options specified in the Request constructor for running the Fastly Image Optimizer. More detailed documentation on all Image Optimizer options is available in the Image Optimizer reference docs.
Parameters
All parameters other than region are optional.
region:RegionWhere image optimizations should occur.auto:AutoEnable optimization features automatically.bgColor:ColorSet the background color of an image.blur:number(0.5-1000) orPercentageSet the blurriness of the output image.brightness:number(-100-100) Set the brightness of the output image.bw:BWAlgorithmConvert an image to black and white.canvas:ObjectIncrease the size of the canvas around an image.contrast:number(-100-100) Set the contrast of the output image.crop:ObjectRemove pixels from an image.disable:DisableDisable functionality that is enabled by default.dpr:numberRatio between physical pixels and logical pixels.enable:EnableEnable functionality that is disabled by default.fit:FitSet how the image will fit within the size bounds provided.format:FormatSpecify the output format to convert the image to.frame:number(must have the value 1) Extract the first frame from an animated image sequence.height:integer(number of pixels) orPercentageResize the height of the image.level:Stringcontaining one of the allowed values Specify the level constraints when converting to video.metadata:MetadataControl which metadata fields are preserved during transformation.optimize:OptimizeAutomatically apply optimal quality compression.orient:OrientChange the cardinal orientation of the image.pad:SidesAdd pixels to the edge of an image.precrop:ObjectRemove pixels from an image before any other transformations occur.profile:ProfileSpecify the profile class of application when converting to video.quality:integer(1-100) Optimize the image to the given compression level for lossy file formatted images.resizeFilter:ResizeFilterSpecify the resize filter used when resizing images.saturation:number(-100-100) Set the saturation of the output image.sharpen:ObjectSet the sharpness of the output image.amount:number(0-10)radius:number(0.5-1000)threshold:integer(0-255)
trim:SidesRemove pixels from the edge of an image.viewbox:number(must have the value 1) Remove explicit width and height properties in SVG output.width:integer(number of pixels) orPercentageResize the width of the image.
Types
Color
Either:
- a 3 or 6 character hexadecimal string
- an
Objectcontaining:r:integer(0-255) Red componentg:integer(0-255) Green componentb:integer(0-255) Blue componenta(optional):number(0.0-1.0) Alpha component
Percentage
A String containing a number suffixed with a percent sign (%).
Position
An Object containing:
- Exactly one of:
x:integer(number of pixels) orPercentageoffsetX:number(interpreted as a percentage)
- Exactly one of:
y:integer(number of pixels) orPercentageoffsetY:number(interpreted as a percentage)
Sides
An Object containing top, bottom, left, and right, all of which are either an integer or Percentage.
Size
An Object containing either:
absolute:Objectwidth:integer(number of pixels) orPercentageheight:integer(number of pixels) orPercentage
ratio:Objectwidth:numberheight:number
Examples
import { Format, Orient, CropMode, Region } from 'fastly:image-optimizer';
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
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
},
blur: '1%',
brightness: -20,
contrast: -20,
height: 600,
level: '4.0',
orient: Orient.FlipVertical,
saturation: 80,
sharpen: { 'amount': 5, 'radius': 6, 'threshold': 44 },
canvas: { 'size': { 'absolute': { 'width': 400, 'height': 400 } } },
crop: { size: { absolute: { width: 200, height: 200 }, mode: CropMode.Safe } },
trim: { top: 10, left: 10, right: 10, bottom: 10 },
pad: { top: 30, left: 30, right: "1%", bottom: 30 }
},
backend: 'w3'
});
}