2025-10-01 19:57:35 +08:00
2025-10-01 19:57:35 +08:00
2025-10-01 17:41:51 +08:00
2025-09-30 12:39:34 +08:00
2025-10-01 15:39:57 +08:00

Edge Image Transformer

An Edge function built with Hono and jSquash for on-demand image resizing and metadata retrieval.

Routes

GET /?url=<image_url>&width=<width>&height=<height>&format=<format>

  • url (required): Absolute URL of the source image.
  • width, height (optional): Desired output dimensions.
    • Supply one or both values to resize while preserving the source aspect ratio.
    • If neither is provided, the original image is returned unchanged.
  • format (optional): Desired output format (e.g., jpeg, png, webp). If not specified, defaults to webp.

Returns: The transformed image encoded in its original format (JPEG, PNG, or WebP). The Content-Type mirrors the source.

GET /meta/?url=<image_url>

Returns JSON:

{
  "width": <number>,
  "height": <number>,
  "thumbHash": "<base64>"
}
  • thumbHash is a ThumbHash placeholder that can be rendered on the client for a quick preview.

Local Development

pnpm install
pnpm dev
  • pnpm dev runs Vite with the Cloudflare Workers dev server adapter.

Build & Deploy

pnpm build   # Emits dist/worker_image_transformations
pnpm deploy  # Builds and deploys via Wrangler

Cloudflare Type Synchronisation

Whenever wrangler.jsonc changes, refresh the generated bindings:

pnpm cf-typegen

This command updates the CloudflareBindings type so that Hono routes have accurate autocompletion.

S
Description
DIYgod mirror: Edge Image Transformer
Readme
101 KiB
Languages
TypeScript 92.9%
JavaScript 7.1%