Skip to main content
Version: 3.36.0

CropMode

Enumerator options for imageOptimizerOptions.crop.mode and imageOptimizerOptions.precrop.mode.

Constants

  • Smart ("smart") Enables content-aware algorithms to attempt to crop the image to the desired aspect ratio while intelligently focusing on the most important visual content, including the detection of faces.
  • Safe ("safe") Allow cropping out-of-bounds regions.

Examples

import { 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,
crop: {
size: { ratio: { width: 4, height: 3 } },
mode: CropMode.Smart,
}
},
backend: 'w3'
});
}