Loading...
Loading...
Store, transform, and deliver optimized images with Cloudflare Images. Covers image upload (API, Worker, Direct Creator Upload), variants, transformations (URL and Workers), bindings, Polish, signed URLs, formats (AVIF, WebP), R2 integration, watermarks. Keywords: Cloudflare Images, image transformations, variants, /cdn-cgi/image/, imagedelivery.net, Polish, AVIF, WebP, signed URLs, Direct Creator Upload, Images binding, R2, watermark.
npx skill4agent add itechmeat/llm-code cloudflare-imagesreferences/upload.mdreferences/transformations.mdreferences/variants.mdreferences/binding.mdreferences/polish.mdreferences/security.mdreferences/pricing.mdsrcset| Mode | Description | Billing |
|---|---|---|
| Storage in Images | Upload images to Cloudflare, serve via variants | Images Stored + Images Delivered |
| Transform remote | Optimize images from any origin (R2, S3, etc.) | Images Transformed (unique/30d) |
curl --request POST \
--url https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1 \
--header 'Authorization: Bearer <API_TOKEN>' \
--header 'Content-Type: multipart/form-data' \
--form file=@./image.jpg<img src="/cdn-cgi/image/width=400,quality=80,format=auto/uploads/hero.jpg" />fetch(imageURL, {
cf: {
image: {
width: 800,
height: 600,
fit: "cover",
format: "auto",
},
},
});https://<ZONE>/cdn-cgi/image/<OPTIONS>/<SOURCE-IMAGE><ZONE>/cdn-cgi/image/<OPTIONS>width=400,quality=80,format=auto<SOURCE-IMAGE>https://imagedelivery.net/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT_NAME>| Option | Description | Example |
|---|---|---|
| Max width in pixels | |
| Max height in pixels | |
| Resize mode | |
| Output format | |
| JPEG/WebP/AVIF quality 1-100 | |
| Crop focus point | |
| Blur radius 1-250 | |
| Sharpening 0-10 | |
| Rotation degrees | |
| Remove pixels from edges | |
| Mode | Behavior |
|---|---|
| Shrink only, never enlarge |
| Fit within dimensions, preserve aspect ratio |
| Fill dimensions, crop if needed |
| Like cover but never enlarges |
| Fit within, add background color |
format=auto| Constraint | Limit |
|---|---|
| Max image dimension | 12,000 pixels |
| Max image area | 100 megapixels |
| Max file size (transformations) | 70 MB |
| Max file size (storage) | 10 MB |
| GIF/WebP animation | 50 megapixels total |
| AVIF output hard limit | 1,200 px (1,600 explicit) |
| Variants per account | 100 |
# wrangler.toml
[images]
binding = "IMAGES"const response = (await env.IMAGES.input(stream).transform({ width: 800 }).transform({ blur: 20 }).output({ format: "image/avif" })).response();const watermark = await fetch("https://example.com/watermark.png");
const image = await fetch("https://example.com/photo.jpg");
const response = (
await env.IMAGES.input(image.body)
.draw(env.IMAGES.input(watermark.body).transform({ width: 100 }), { bottom: 10, right: 10, opacity: 0.75 })
.output({ format: "image/avif" })
).response();const info = await env.IMAGES.info(stream);
// { format, fileSize, width, height }<img srcset="/cdn-cgi/image/width=320/photo.jpg 320w, /cdn-cgi/image/width=640/photo.jpg 640w, /cdn-cgi/image/width=1280/photo.jpg 1280w" sizes="(max-width: 640px) 100vw, 640px" src="/cdn-cgi/image/width=640/photo.jpg" alt="Responsive image" />fetch(imageURL, {
cf: {
image: {
width: 200,
height: 200,
fit: "cover",
gravity: "face",
zoom: 0.5, // 0 = more background, 1 = tight crop
},
},
});# Get one-time upload URL
curl --request POST \
https://api.cloudflare.com/client/v4/accounts/{account_id}/images/v2/direct_upload \
--header "Authorization: Bearer <API_TOKEN>"
# Response: { "uploadURL": "https://upload.imagedelivery.net/..." }const image = await fetch("https://example.com/image.png");
const bytes = await image.bytes();
const formData = new FormData();
formData.append("file", new File([bytes], "image.png"));
await fetch(`https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/images/v1`, {
method: "POST",
headers: { Authorization: `Bearer ${TOKEN}` },
body: formData,
});/*requireSignedURLs=truecacheKeyCf-Resized| Code | Meaning |
|---|---|
| 9401 | Invalid transformation options |
| 9402 | Image too large |
| 9403 | Request loop detected |
| 9422 | Free tier limit exceeded (5,000/month) |
| 9520 | Unsupported format |
cloudflare-workerscloudflare-pagescloudflare-r2