Skip to content

Conversation

@TartanLlama
Copy link
Contributor

@TartanLlama TartanLlama commented Nov 11, 2025

Adds support for Image Optimizer with an added imageOptimizerOptions parameter for fetch.

Example usage:

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'
  });
}

Also upgrades Viceroy to version 15 in CI, as a more recent version is required for the stubbed IO hostcall.

Fixes #1194

@TartanLlama TartanLlama marked this pull request as ready for review November 12, 2025 17:52
@TartanLlama TartanLlama requested a review from zkat November 14, 2025 15:35
@TartanLlama TartanLlama merged commit c3dd3de into main Nov 18, 2025
37 of 54 checks passed
@TartanLlama TartanLlama deleted the sy/image-optimizer branch November 18, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ImageOpto to JS SDK

3 participants