Skip to content

Add Image Optimization Support #59

@posborne

Description

@posborne

Overview

Add support for Fastly's Image Optimizer API, enabling on-the-fly image transformation and optimization.

WIT Interface

interface image-optimizer {
  use http-body.{body};
  use http-req.{request};
  use http-resp.{response-with-body};
  use types.{error};
  use backend.{backend};

  resource extra-image-optimizer-transform-options;

  record image-optimizer-transform-options {
    sdk-claims-opts: option<string>,
    extra: option<borrow<extra-image-optimizer-transform-options>>,
  }

  transform-image-optimizer-request: func(origin-image-request: borrow<request>, origin-image-request-body: option<body>, origin-image-request-backend: borrow<backend>, io-transform-options: image-optimizer-transform-options) -> result<response-with-body, error>;
}

WIT bindings: stubs/wit_world/imports/image_optimizer.py

API Design

  • Simple function-based API: transform_image(request, body, backend, options)
  • ImageOptimizerOptions dataclass for transformation parameters
  • Returns tuple of (Response, Body) with optimized image
  • Body should be io.IOBase-compatible for streaming large images
  • Supports query parameter-based transformations (width, height, format, quality, etc.)
  • Integration with Backend and Request/Response APIs

Cross-SDK Comparison: Rust has transform_image_optimizer_request(), JS has similar. Go support may vary. This is a specialized/premium feature - Python wrapper should match Rust's approach with transform function accepting request, backend, and options.

Viceroy Testing

Image Optimizer is NOT supported in Viceroy. The implementation returns Error::Unsupported for all calls (src/component/image_optimizer.rs:14, src/wiggle_abi/image_optimizer.rs:18).

Tests should:

  • Verify the API wrapper exists and accepts correct parameters
  • Skip or mark as expected to fail any tests that actually call transform_image_optimizer_request()
  • Focus on testing parameter validation, type conversions, and error handling for Unsupported errors

This API is primarily testable in production or staging environments.

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions