Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/images/gotchas.md
1# Gotchas & Best Practices23## Fit Modes45| Mode | Best For | Behavior |6|------|----------|----------|7| `cover` | Hero images, thumbnails | Fills space, crops excess |8| `contain` | Product images, artwork | Preserves full image, may add padding |9| `scale-down` | User uploads | Never enlarges |10| `crop` | Precise crops | Uses gravity |11| `pad` | Fixed aspect ratio | Adds background |1213## Format Selection1415```typescript16format: 'auto' // Recommended - negotiates best format17```1819**Support:** AVIF (Chrome 85+, Firefox 93+, Safari 16.4+), WebP (Chrome 23+, Firefox 65+, Safari 14+)2021## Quality Settings2223| Use Case | Quality |24|----------|---------|25| Thumbnails | 75-80 |26| Standard | 85 (default) |27| High-quality | 90-95 |2829## Common Errors3031### 5403: "Image transformation failed"32- Verify `width`/`height` ≤ 1200033- Check `quality` 1-100, `dpr` 1-334- Don't combine incompatible options3536### 9413: "Rate limit exceeded"37Implement caching and exponential backoff:38```typescript39for (let i = 0; i < 3; i++) {40try { return await env.IMAGES.input(buffer).transform({...}).output(); }41catch { await new Promise(r => setTimeout(r, 2 ** i * 1000)); }42}43```4445### 5401: "Image too large"46Pre-process images before upload (max 100MB, 12000×12000px)4748### 5400: "Invalid image format"49Supported: JPEG, PNG, GIF, WebP, AVIF, SVG5051### 401/403: "Unauthorized"52Verify API token has `Cloudflare Images → Edit` permission5354## Limits5556| Resource | Limit |57|----------|-------|58| Max input size | 100MB |59| Max dimensions | 12000×12000px |60| Quality range | 1-100 |61| DPR range | 1-3 |62| API rate limit | ~1200 req/min |6364## AVIF Gotchas6566- **Slower encoding**: First request may have higher latency67- **Browser detection**:68```typescript69const format = /image\/avif/.test(request.headers.get('Accept') || '') ? 'avif' : 'webp';70```7172## Anti-Patterns7374```typescript75// ❌ No caching - transforms every request76return env.IMAGES.input(buffer).transform({...}).output().response();7778// ❌ cover without both dimensions79transform({ width: 800, fit: 'cover' })8081// ✅ Always set both for cover82transform({ width: 800, height: 600, fit: 'cover' })8384// ❌ Exposes API token to client85// ✅ Use Direct Creator Upload (patterns.md)86```8788## Debugging8990```typescript91// Check response headers92console.log('Content-Type:', response.headers.get('Content-Type'));9394// Test with curl95// curl -I "https://imagedelivery.net/{hash}/{id}/width=800,format=avif"9697// Monitor logs98// npx wrangler tail99```100