Cloudflare Image Converter

A Cloudflare Worker 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; at least one must be provided.
    • If only width is supplied the height is inferred from the source aspect ratio, and vice versa.
  • 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%