Loading...
Loading...
Compare original and translation side by side
references/upload.mdreferences/transformations.mdreferences/variants.mdreferences/binding.mdreferences/polish.mdreferences/security.mdreferences/pricing.mdreferences/upload.mdreferences/transformations.mdreferences/variants.mdreferences/binding.mdreferences/polish.mdreferences/security.mdreferences/pricing.mdsrcsetsrcset| 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) |
| 模式 | 描述 | 计费方式 |
|---|---|---|
| 存储至Images | 将图片上传至Cloudflare,通过变体交付 | 存储图片量 + 交付图片量 |
| 转换远程图片 | 优化来自任意源(R2、S3等)的图片 | 图片转换量(30天内唯一请求) |
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.jpgcurl --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" /><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",
},
},
});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://<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>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 | |
| 选项 | 描述 | 示例 |
|---|---|---|
| 最大宽度(像素) | |
| 最大高度(像素) | |
| 缩放模式 | |
| 输出格式 | |
| JPEG/WebP/AVIF质量(1-100) | |
| 裁剪焦点 | |
| 模糊半径(1-250) | |
| 锐化程度(0-10) | |
| 旋转角度(度) | |
| 移除边缘像素 | |
| 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 |
| 模式 | 行为 |
|---|---|
| 仅缩小,绝不放大 |
| 适配尺寸,保留宽高比 |
| 填充尺寸,必要时裁剪 |
| 类似cover,但绝不放大 |
| 适配尺寸,添加背景色 |
format=autoformat=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 |
| 约束条件 | 限制值 |
|---|---|
| 最大图片尺寸 | 12,000像素 |
| 最大图片面积 | 1亿像素 |
| 转换时最大文件大小 | 70 MB |
| 存储时最大文件大小 | 10 MB |
| GIF/WebP动图 | 总像素不超过5000万 |
| AVIF输出硬限制 | 1200像素(显式设置为1600) |
| 每个账户的变体数量 | 100 |
undefinedundefinedundefinedundefinedconst response = (await env.IMAGES.input(stream).transform({ width: 800 }).transform({ blur: 20 }).output({ format: "image/avif" })).response();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 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 }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" /><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
},
},
});fetch(imageURL, {
cf: {
image: {
width: 200,
height: 200,
fit: "cover",
gravity: "face",
zoom: 0.5, // 0 = 保留更多背景,1 = 紧密裁剪
},
},
});undefinedundefinedundefinedundefinedconst 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,
});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=truecacheKey/*requireSignedURLs=truecacheKeyCf-ResizedCf-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 |
| 错误码 | 含义 |
|---|---|
| 9401 | 无效的转换选项 |
| 9402 | 图片过大 |
| 9403 | 检测到请求循环 |
| 9422 | 免费版限额已超出(每月5000次) |
| 9520 | 不支持的格式 |
cloudflare-workerscloudflare-pagescloudflare-r2cloudflare-workerscloudflare-pagescloudflare-r2