tigris-image-optimization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTigris Image Optimization
Tigris 图片优化
Resize, crop, and optimize images stored in Tigris. Generate thumbnails on upload, serve responsive images, and leverage Tigris's global CDN for fast delivery.
调整、裁剪并优化存储在Tigris中的图片。上传时生成缩略图,提供响应式图片,借助Tigris的全球CDN实现快速交付。
Strategy Overview
策略概览
| Approach | When to Use | Pros | Cons |
|---|---|---|---|
| Process on upload | Thumbnails, fixed sizes | Fast serving, predictable | Storage cost per variant |
| Process on request | Many size variations | Flexible, less storage | Latency on first request |
| Client-side resize | Before upload | Saves bandwidth, fast upload | Less control over quality |
Recommended: Process on upload for known sizes (avatar, thumbnail, cover). Use public buckets for CDN delivery — Tigris serves public files from the nearest global edge automatically.
| 方法 | 适用场景 | 优点 | 缺点 |
|---|---|---|---|
| 上传时处理 | 缩略图、固定尺寸场景 | 交付速度快,效果可预期 | 每个变体都会产生存储成本 |
| 请求时处理 | 多种尺寸变体场景 | 灵活,存储成本更低 | 首次请求存在延迟 |
| 客户端调整大小 | 上传前处理 | 节省带宽,上传速度快 | 对质量的控制度较低 |
推荐方案: 针对已知尺寸(头像、缩略图、封面图)采用上传时处理。使用公共存储桶进行CDN交付——Tigris会自动从最近的全球边缘节点提供公共文件。
Upload-Time Processing (General Pattern)
上传时处理(通用模式)
Generate variants when a file is uploaded, store each variant as a separate object:
avatars/user-123.jpg # original
avatars/user-123-thumb.jpg # 100x100
avatars/user-123-medium.jpg # 400x400
avatars/user-123-large.jpg # 800x800Use for images that need fast, CDN-backed delivery.
access: "public"文件上传时生成不同变体,将每个变体作为单独的对象存储:
avatars/user-123.jpg # original
avatars/user-123-thumb.jpg # 100x100
avatars/user-123-medium.jpg # 400x400
avatars/user-123-large.jpg # 800x800需要快速CDN交付的图片请设置。
access: "public"Framework Guides
框架指南
Read the resource file for your framework:
- Next.js — Read for next/image config and Sharp processing
./resources/nextjs.md - Remix — Read for Sharp in action functions and responsive srcset
./resources/remix.md - Express — Read for Sharp middleware with Multer
./resources/express.md - Rails — Read for Active Storage variants
./resources/rails.md - Django — Read for django-imagekit and Pillow processing
./resources/django.md - Laravel — Read for Intervention Image
./resources/laravel.md
阅读对应框架的资源文件:
- Next.js — 阅读了解next/image配置和Sharp处理方案
./resources/nextjs.md - Remix — 阅读了解action函数中的Sharp用法和响应式srcset实现
./resources/remix.md - Express — 阅读了解搭配Multer的Sharp中间件用法
./resources/express.md - Rails — 阅读了解Active Storage变体用法
./resources/rails.md - Django — 阅读了解django-imagekit和Pillow处理方案
./resources/django.md - Laravel — 阅读了解Intervention Image用法
./resources/laravel.md
CDN Delivery
CDN交付
Tigris public buckets serve files from the nearest global edge — no separate CDN setup needed.
Cache headers for images:
typescript
await put("images/hero.jpg", buffer, {
access: "public",
contentType: "image/jpeg",
});For immutable content-hashed filenames (e.g., ), use long cache times. For mutable paths, use shorter TTLs or ETags.
hero-abc123.jpgTigris公共存储桶会从最近的全球边缘节点提供文件,无需额外配置CDN。
图片缓存头配置:
typescript
await put("images/hero.jpg", buffer, {
access: "public",
contentType: "image/jpeg",
});对于不可变的内容哈希文件名(例如),可设置长缓存时间。对于可变路径,使用更短的TTL或ETag。
hero-abc123.jpgCritical Rules
核心规则
Always: Use for images served to users (enables CDN) | Generate thumbnails at upload time for known sizes | Use WebP/AVIF for smaller file sizes | Set explicit
access: "public"contentTypeNever: Process images on every request without caching | Store only originals if you always serve thumbnails | Resize in the browser after downloading full-size images
必须遵守: 对外提供的图片需设置(启用CDN)| 针对已知尺寸在上传时生成缩略图 | 使用WebP/AVIF格式减小文件体积 | 设置明确的
access: "public"contentType禁止操作: 未加缓存的情况下每次请求都处理图片 | 如果需要频繁提供缩略图,仅存储原文件 | 下载完全尺寸图片后再在浏览器中调整大小
Related Skills
相关技能
- tigris-file-uploads — Full upload patterns per framework
- tigris-egress-optimizer — Reduce bandwidth costs from image serving
- tigris-file-uploads — 各框架的完整上传模式
- tigris-egress-optimizer — 降低图片交付的带宽成本
Official Documentation
官方文档
- Tigris SDK: https://www.tigrisdata.com/docs/sdks/tigris/
- Sharp: https://sharp.pixelplumbing.com/
- Tigris SDK: https://www.tigrisdata.com/docs/sdks/tigris/
- Sharp: https://sharp.pixelplumbing.com/