Image Transformation, Hosting, Variants, and Worker Bindings
How edge image optimization works: remote transformations, hosted delivery, variants, uploads, Workers bindings, flows, limits, pricing, and verification.
This page summarizes Cloudflare Images documentation on storing, transforming, and delivering images at the edge. Images supports two main approaches: optimize images on your own origin (or R2) without pre-generating every size, or upload into Images for managed storage and delivery.
When to use hosted storage vs remote transformation
Section titled “When to use hosted storage vs remote transformation”Cloudflare offers two integration paths for Images.
Cloudflare offers two integration paths for Images:
— Cloudflare, Images
Bring your own storage means images stay on your origin or in object storage; Cloudflare pulls, transforms, and caches optimized versions. Host in Images means you upload once and serve through imagedelivery.net or a custom domain with predefined variants.
Store in R2 and use Images for transformations if you want to build your own custom image pipeline or need fine-grained control over storage, such as bucket-level access management or object lifecycle rules. This is typically the most cost-effective approach for image optimization.
Store in Images if you want a fully managed solution with the least configuration.
— Cloudflare, Introduction
| Goal | Typical choice |
|---|---|
| Keep URLs unchanged on origin; compress in place | Polish (not the same as URL-based Images) |
Resize/crop/watermark with new URLs or /cdn-cgi/image/ paths |
Transformations |
| User uploads, thumbnails, signed private URLs | Hosted images + storage |
| Custom pipelines (watermark, format negotiation, hide origin) | Workers binding or cf.image on fetch() |
Polish automatically optimizes all images served from your origin server. It keeps the same image URLs… Cloudflare Images API allows you to create new images with resizing, cropping, watermarks, and other processing applied. These images get their own new URLs… Images created this way are already optimized, and there is no need to apply Polish to them.
— Cloudflare, Polish
Remote images (/cdn-cgi/image/): how on-the-fly transformation works
Section titled “Remote images (/cdn-cgi/image/): how on-the-fly transformation works”A transformation is a request to optimize a remote image stored outside Images storage.
Transformations are requests to optimize and manipulate remote images that are stored outside of Images.
— Cloudflare, Overview
Enable the feature per zone under Images > Transformations, then request transforms with a formatted URL:
https://<ZONE>/cdn-cgi/image/<OPTIONS>/<SOURCE-IMAGE>When the browser requests a transformed image, Cloudflare checks the edge cache for a previously optimized version with the same parameters: On a cache HIT — Cloudflare serves the optimized image directly from the edge… On a cache MISS — Cloudflare fetches the original image from the source origin, applies the requested parameters…
— Cloudflare, Overview
Each unique combination of source image and parameters is cached and billed separately within a calendar month; repeat serves of the same transformation do not add billable usage again that month.
Allowed source origins: lock down where transforms may pull from
Section titled “Allowed source origins: lock down where transforms may pull from”By default, only sources on the same zone as the transformation are accepted.
If you request a transformation with a source image from outside your allowed origins, then the image will be rejected.
— Cloudflare, Define source origins
Use allowed origins with domain, optional path prefix, or *.example.com for subdomains. Setting any origin is less secure because third parties could use your zone to transform arbitrary public URLs.
Transformation flows: automate optimization without changing markup
Section titled “Transformation flows: automate optimization without changing markup”Flows pair conditions (extension, path, query params) with optimization actions—useful for format=auto, width=auto, or path-based rules.
Flows are automated rules that pair conditions (such as file extension, URL path, or query parameter) with parameters. Set up a flow to automatically apply image optimization to matching requests on your zone without writing code or changing URLs.
— Cloudflare, Create transformation flows
Flows run top to bottom; only the first match applies. They run after redirect rules and skip requests already from the Images service to avoid loops. Provider flows currently include Fastly Image Optimizer parameter mapping; custom flows are defined in the dashboard under Images > Transformations > Automation.
Hosted images: variants, delivery URLs, and uploads
Section titled “Hosted images: variants, delivery URLs, and uploads”A hosted image lives in Images storage. Delivery typically looks like:
https://imagedelivery.net/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT_NAME>Variants are predefined resize rules (up to 100 per account; public cannot be deleted). Flexible variants add dynamic resizing beyond fixed variant presets.
Variants let you specify how images should be resized for different use cases. By default, images are served with a public variant, but you can create up to 100 variants to fit your needs.
— Cloudflare, Create predefined variants
SVG is delivered sanitized and not resized; blur variants cannot target SVG (Apply blur).
Direct Creator Upload: let users upload without exposing API tokens
Section titled “Direct Creator Upload: let users upload without exposing API tokens”The Direct Creator Upload feature in Cloudflare Images lets your users upload images with a one-time upload URL without exposing your API key or token to the client.
— Cloudflare, Accept user-uploaded images
Use POST accounts/:account_identifier/images/v2/direct_upload (v1 direct upload was deprecated July 1, 2022). Default uploadURL expiry is 30 minutes; custom expiry is between 2 minutes and 6 hours. Images with a custom ID cannot use requireSignedURLs=true.
The same pattern exists on the Workers binding via createDirectUpload().
Private images and custom domains
Section titled “Private images and custom domains”Require signed URL tokens per image, or generate signed delivery URLs server-side (Worker signedUrl() or HMAC signing example). Private images do not support custom paths.
Custom domains use:
https://example.com/cdn-cgi/imagedelivery/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT_NAME>See Serve images from custom domains and URL rewrite rules for path customization.
Workers: cf.image vs Images binding
Section titled “Workers: cf.image vs Images binding”Use Cloudflare’s image optimization capabilities through: URL interface… Workers — Bind the Images API directly to your Worker or set the cf.image options on a fetch subrequest…
— Cloudflare, Features
| Interface | Best for |
|---|---|
URL /cdn-cgi/image/… or fetch(url, { cf: { image: {…} } }) |
Markup-friendly resizing, Next.js loader, transformation flows |
env.IMAGES binding (input → transform / draw → output) |
Bytes from R2, request bodies, hosted images without public URLs; chained overlays and custom operation order |
Configure the binding in Wrangler:
{ "images": { "binding": "IMAGES" }}The Images binding lets you optimize and manipulate images directly in a Worker. Unlike the URL interface, which requires images to be accessible through a URL, the binding works with raw image bytes.
— Cloudflare, Optimize with Workers
env.IMAGES.hosted supports upload, list, metadata filters, update, delete, and direct upload links without REST tokens (Manage hosted images with Workers).
Billing for the binding matches URL transforms: per unique transformation per calendar month; .info() is not billed (changelog).
Control origin access with Worker logic
Section titled “Control origin access with Worker logic”Workers can hide the real origin URL, cap allowed widths, map preset names to dimensions, and fetch authenticated origins when using origin-auth: share-publicly with signed headers—see Control origin access.
Responsive images: srcset and width=auto
Section titled “Responsive images: srcset and width=auto”Point srcset entries at the same source with different width (and dpr) parameters instead of pre-generating files (Make responsive images).
width=auto chooses width via client hints (preferred) or user-agent fallback, snapping to breakpoints (default 320;768;960;1200). Enable hints with Delegate-CH meta or response headers documented on that page.
Limits, formats, and pricing
Section titled “Limits, formats, and pricing”Key limits are in Limits and formats:
| Context | File size | Binding input |
|---|---|---|
| Remote transform | 100 MB | — |
| Hosted upload | 10 MB | input() max 20 MB |
HEIC can be ingested and served as AVIF, WebP, JPEG, or PNG (HEIC support).
Free plan: 5,000 unique transformations/month; beyond that, new transforms return error 9422 (Pricing). Paid: transformations, storage, and delivery are metered separately; hosted delivery via imagedelivery.net counts as Images Delivered, while binding optimization of hosted bytes counts as Images Transformed.
Monitor usage under Images & Stream > Transformations > Analytics.
Common mistakes
Section titled “Common mistakes”- Enabling a resize Worker on
/*, which blocks non-image traffic (Transform via fetch). - Resize worker and origin paths overlap, causing loops—check
Viaforimage-resizingand bypass re-resizing (troubleshooting, Transform via fetch). - Testing transforms only in the dashboard editor; deploy and test in a browser (Control origin access, Transform via fetch).
- Expecting
Cf-Resizedon requests when transformations are disabled or another Worker breaks the resize chain (Troubleshooting). - Using custom image IDs then requiring signed URLs (not supported) (Upload via custom path, Direct creator upload).
- Stacking Polish (or other optimizers) on top of Images (multiple optimizations).
How to check this on your site
Section titled “How to check this on your site”- Confirm transformations are enabled for your zone in the Transformations overview (dashboard: Images > Transformations).
- Request a test URL such as
/cdn-cgi/image/width=200/<path-to-image>and verify response headers include resizing signals (e.g.Cf-Resizedwhen optimization ran) per Troubleshooting. - For hosted images, open a delivery URL from Developer Resources and confirm the variant and format behave as expected.
- Review Transformation analytics to see URL-based vs binding traffic and top origins or Workers.
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page disagrees with your setup or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact sentence you want clarified or corrected.