Skip to main content
Version: 3.36.0

Fit

Enumerator options for imageOptimizerOptions.fit.

Constants

  • Bounds ("bounds") Resize the image to fit entirely within the specified region, making one dimension smaller if needed.
  • Cover ("cover") Resize the image to entirely cover the specified region, making one dimension larger if needed.
  • Crop ("crop") Resize and crop the image centrally to exactly fit the specified region.

Examples

import { Fit, 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,
width: 150,
height; 150,
fit: Fit.Bounds
},
backend: 'w3'
});
}