netlify-image-cdn
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNetlify Image CDN
Netlify Image CDN
Every Netlify site has a built-in endpoint for on-the-fly image transformation. No configuration required for local images.
/.netlify/images每个Netlify站点都内置了端点,用于实时图片转换。本地图片无需额外配置。
/.netlify/imagesBasic Usage
基础用法
html
<img src="/.netlify/images?url=/photo.jpg&w=800&h=600&fit=cover&q=80" />html
<img src="/.netlify/images?url=/photo.jpg&w=800&h=600&fit=cover&q=80" />Query Parameters
查询参数
| Param | Description | Values |
|---|---|---|
| Source image path (required) | Relative path or absolute URL |
| Width in pixels | Any positive integer |
| Height in pixels | Any positive integer |
| Resize behavior | |
| Crop alignment (with | |
| Output format | |
| Quality (lossy formats) | 1-100 (default: 75) |
When is omitted, Netlify auto-negotiates the best format based on browser support (preferring , then ).
fmwebpavif| 参数 | 说明 | 取值 |
|---|---|---|
| 源图片路径(必填) | 相对路径或绝对URL |
| 宽度(像素) | 任意正整数 |
| 高度(像素) | 任意正整数 |
| 缩放行为 | |
| 裁剪对齐(配合 | |
| 输出格式 | |
| 质量(有损格式) | 1-100(默认:75) |
当省略时,Netlify会根据浏览器支持自动协商最佳格式(优先选择,其次是)。
fmwebpavifRemote Image Allowlisting
远程图片白名单
External images must be explicitly allowed in :
netlify.tomltoml
[images]
remote_images = ["https://example\\.com/.*", "https://cdn\\.images\\.com/.*"]Values are regex patterns.
外部图片必须在中明确允许:
netlify.tomltoml
[images]
remote_images = ["https://example\\.com/.*", "https://cdn\\.images\\.com/.*"]取值为正则表达式模式。
Clean URL Rewrites
简洁URL重写
Create user-friendly image URLs with redirects:
toml
undefined通过重定向创建用户友好的图片URL:
toml
undefinedBasic optimization
基础优化
[[redirects]]
from = "/img/*"
to = "/.netlify/images?url=/:splat"
status = 200
[[redirects]]
from = "/img/*"
to = "/.netlify/images?url=/:splat"
status = 200
Preset: thumbnail
预设:缩略图
[[redirects]]
from = "/img/thumb/:key"
to = "/.netlify/images?url=/uploads/:key&w=150&h=150&fit=cover"
status = 200
[[redirects]]
from = "/img/thumb/:key"
to = "/.netlify/images?url=/uploads/:key&w=150&h=150&fit=cover"
status = 200
Preset: hero
预设:首图
[[redirects]]
from = "/img/hero/:key"
to = "/.netlify/images?url=/uploads/:key&w=1200&h=675&fit=cover"
status = 200
undefined[[redirects]]
from = "/img/hero/:key"
to = "/.netlify/images?url=/uploads/:key&w=1200&h=675&fit=cover"
status = 200
undefinedCaching
缓存
- Transformed images are cached at the CDN edge automatically
- Cache invalidates on new deploys
- Set cache headers on source images to control caching:
toml
[[headers]]
for = "/uploads/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"- 转换后的图片会自动在CDN边缘缓存
- 缓存会在新部署时失效
- 可设置源图片的缓存头来控制缓存:
toml
[[headers]]
for = "/uploads/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"User-Uploaded Images
用户上传图片
Combine Netlify Functions (upload handler) + Netlify Blobs (storage) + Image CDN (serving/transforming) to build a complete user-uploaded image pipeline. See references/user-uploads.md for the full pattern.
结合Netlify Functions(上传处理器)+ Netlify Blobs(存储)+ Image CDN(提供/转换服务),构建完整的用户上传图片流程。完整模式请参考references/user-uploads.md。