Skip to content

secondsky/claude-skills / plugins/cloudflare-images/skills/cloudflare-images

cloudflare-images

Unverified

This skill should be used when the user asks to "upload images to Cloudflare", "implement direct creator upload", "configure image transformations", "optimize WebP/AVIF", "create image variants", "generate signed URLs", "add image watermarks", "integrate with Next.js/Remix", "configure webhooks", "debug CORS errors", "troubleshoot error 5408/9401-9413", or "build responsive images with Cloudflare Images API".

FileKindSize
SKILL.mdskill md13.9 KB
assets/diagrams/direct-upload-workflow.mdmarkdown5.0 KB
assets/diagrams/transformation-pipeline.mdmarkdown8.2 KB
assets/diagrams/variants-structure.mdmarkdown10.6 KB
examples/basic-upload/.env.exampleother474 B
examples/basic-upload/README.mdmarkdown6.5 KB
examples/basic-upload/package.jsonmanifest542 B
examples/basic-upload/public/index.htmlother12.7 KB
examples/basic-upload/src/index.tsscript2.7 KB
examples/basic-upload/wrangler.jsoncother378 B
examples/private-images/.env.exampleother631 B
examples/private-images/README.mdmarkdown12.5 KB
examples/private-images/package.jsonmanifest741 B
examples/private-images/public/index.htmlother18.0 KB
examples/private-images/src/index.tsscript5.2 KB
examples/private-images/wrangler.jsoncother427 B
examples/responsive-gallery/README.mdmarkdown4.3 KB
references/api-reference.mdmarkdown8.1 KB
references/content-credentials.mdmarkdown11.6 KB
references/custom-domains.mdmarkdown10.5 KB
references/direct-upload-complete-workflow.mdmarkdown11.2 KB
references/format-optimization.mdmarkdown7.2 KB
references/framework-integration.mdmarkdown15.4 KB
references/overlays-watermarks.mdmarkdown11.1 KB
references/polish-compression.mdmarkdown10.4 KB
references/responsive-images-patterns.mdmarkdown6.1 KB
references/setup-guide.mdmarkdown3.8 KB
references/signed-urls-guide.mdmarkdown7.5 KB
references/sourcing-kit.mdmarkdown15.0 KB
references/top-errors.mdmarkdown11.7 KB
references/transformation-options.mdmarkdown6.4 KB
references/variants-guide.mdmarkdown6.7 KB
references/webhooks-guide.mdmarkdown11.8 KB
scripts/analyze-usage.shexecutablescript6.6 KB
scripts/check-versions.shexecutablescript3.3 KB
scripts/generate-signed-url.shexecutablescript4.4 KB
scripts/test-upload.shexecutablescript4.4 KB
scripts/validate-variants.shexecutablescript5.2 KB
templates/batch-upload.tsscript7.8 KB
templates/direct-creator-upload-backend.tsscript5.4 KB
templates/direct-creator-upload-frontend.htmlother8.4 KB
templates/nextjs-integration.tsxother11.4 KB
templates/overlay-watermark.tsscript13.7 KB
templates/package.jsonmanifest387 B
templates/remix-integration.tsxother15.0 KB
templates/responsive-images-srcset.htmlother8.0 KB
templates/signed-urls-generation.tsscript6.6 KB
templates/transform-via-url.tsscript6.5 KB
templates/transform-via-workers.tsscript8.7 KB
templates/upload-api-basic.tsscript3.8 KB
templates/upload-via-url.tsscript4.9 KB
templates/variants-management.tsscript7.0 KB
templates/webhook-handler.tsscript8.8 KB
templates/wrangler-images-binding.jsoncother1.2 KB

examples/responsive-gallery/README.md

View on GitHub
# Responsive Gallery Example

Complete responsive image gallery using Cloudflare Images with srcset, lazy loading, and variant optimization.

## Features

- ✅ Responsive images with `srcset` and `sizes`
- ✅ Lazy loading for performance
- ✅ Named variants for common sizes
- ✅ Masonry grid layout
- ✅ Lightbox for full-size viewing
- ✅ WebP/AVIF automatic format negotiation
- ✅ CDN caching

## Live Demo Structure

```
responsive-gallery/
├── README.md              # This file
├── index.html             # Gallery UI
└── images.json            # Image metadata (IDs, alt text)
```

## Implementation

### HTML Structure

```html
<div class="gallery">
  <div class="gallery-item" data-image-id="abc123">
    <img
      src="https://imagedelivery.net/{hash}/abc123/thumbnail"
      srcset="
        https://imagedelivery.net/{hash}/abc123/thumbnail 300w,
        https://imagedelivery.net/{hash}/abc123/medium 600w,
        https://imagedelivery.net/{hash}/abc123/large 1200w
      "
      sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
      alt="Product photo"
      loading="lazy"
      decoding="async"
    />
  </div>
</div>
```

### Variants Configuration

Create these variants using `/generate-variant` command:

```json
{
  "thumbnail": { "width": 300, "height": 300, "fit": "cover", "quality": 80 },
  "medium": { "width": 600, "height": 600, "fit": "scale-down", "quality": 85 },
  "large": { "width": 1200, "height": 1200, "fit": "scale-down", "quality": 90 }
}
```

### Responsive Behavior

- **Mobile (<640px)**: Loads `thumbnail` variant (300px)
- **Tablet (640-1024px)**: Loads `medium` variant (600px)
- **Desktop (>1024px)**: Loads `large` variant (1200px)
- **Retina displays**: Automatically serves higher resolution

### Performance Optimizations

1. **Lazy Loading**: Images load as user scrolls
2. **Decoding Async**: Non-blocking image decode
3. **Format Auto**: WebP/AVIF served automatically (25-50% smaller)
4. **CDN Caching**: Cached globally at edge locations
5. **Named Variants**: Pre-defined sizes for consistency

### Lighthouse Scores

Expected scores with optimizations:

- **Performance**: 95-100
- **Largest Contentful Paint (LCP)**: <2.5s
- **Cumulative Layout Shift (CLS)**: <0.1
- **Total Blocking Time (TBT)**: <200ms

## Setup

### 1. Create Variants

```bash
# Use the generate-variant command for each size
/generate-variant

# Or via API:
curl -X POST \
  "https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/images/v1/variants" \
  -H "Authorization: Bearer ${CF_API_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"id": "thumbnail", "options": {"width": 300, "height": 300, "fit": "cover"}}'
```

### 2. Configure Image Data

Edit `images.json` with your image IDs:

```json
[
  {
    "id": "2cdc28f0-017a-49c4-9ed7-87056c83901",
    "alt": "Product 1",
    "title": "Modern Chair"
  },
  {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "alt": "Product 2",
    "title": "Wooden Table"
  }
]
```

### 3. Open Gallery

```bash
# Serve locally
npx serve .

# Or open directly
open index.html
```

## Advanced Features

### Lightbox Implementation

```javascript
// Click image to view full size
item.addEventListener('click', () => {
  const lightbox = document.createElement('div');
  lightbox.className = 'lightbox';
  lightbox.innerHTML = `
    <img src="https://imagedelivery.net/${ACCOUNT_HASH}/${imageId}/large?format=auto" />
  `;
  document.body.appendChild(lightbox);
});
```

### Infinite Scroll

```javascript
// Load more images on scroll
const observer = new IntersectionObserver((entries) => {
  if (entries[0].isIntersecting) {
    loadMoreImages();
  }
});

observer.observe(document.querySelector('.load-more-trigger'));
```

### Search and Filter

```javascript
// Filter gallery by search term
function filterGallery(searchTerm) {
  const items = document.querySelectorAll('.gallery-item');
  items.forEach(item => {
    const alt = item.querySelector('img').alt.toLowerCase();
    item.style.display = alt.includes(searchTerm.toLowerCase()) ? 'block' : 'none';
  });
}
```

## Related Examples

- **Basic Upload**: Minimal upload implementation
- **Private Images**: Signed URLs for access control

## Related References

- **Responsive Images**: `references/responsive-images-patterns.md`
- **Variants Guide**: `references/variants-guide.md`
- **Format Optimization**: `references/format-optimization.md`
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall