---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://framesfield.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
title: "Sharp WebP, AVIF and Responsive Image Skill"
description: "Installable SKILL.md teaching Claude Code, Cursor, and Codex to batch-convert raw AI PNG renders (FLUX 3 Image, Seedream 5.5, Ideogram 4.6, OpenAI GPT-Image-2.6) into responsive 640px, 1280px, and 1920px WebP and AVIF assets using Node.js sharp—stripping EXIF bloat, preserving alpha cutouts, and emitting exact width, height, srcset, and LCP loading attributes."
canonical: "https://framesfield.com/skills/sharp-responsive-webp-image-pipeline-skill"
---

# Sharp WebP, AVIF and Responsive Image Skill

> Installable SKILL.md teaching Claude Code, Cursor, and Codex to batch-convert raw AI PNG renders (FLUX 3 Image, Seedream 5.5, Ideogram 4.6, OpenAI GPT-Image-2.6) into responsive 640px, 1280px, and 1920px WebP and AVIF assets using Node.js sharp—stripping EXIF bloat, preserving alpha cutouts, and emitting exact width, height, srcset, and LCP loading attributes.

- **Canonical URL:** https://framesfield.com/skills/sharp-responsive-webp-image-pipeline-skill
- **Raw Payload URL:** https://framesfield.com/raw/skills/sharp-responsive-webp-image-pipeline-skill
- **Asset Type:** SKILL.md
- **Compatible Hosts:** Claude Code, Cursor, Codex
- **Target Creative Tool:** Node.js Sharp / WebP & AVIF
- **License:** MIT
- **Last Verified:** 2026-11-30
- **Source Reference:** https://sharp.pixelplumbing.com/

## Setup & Install

```bash
mkdir -p .claude/skills/sharp-responsive-images
curl -fsSL https://framesfield.com/raw/skills/sharp-responsive-webp-image-pipeline-skill -o .claude/skills/sharp-responsive-images/SKILL.md

```

## Copyable Asset (SKILL.md)

````markdown
---
name: sharp-responsive-images
description: Batch-optimize raw AI image exports (PNG/JPG) into responsive 640px, 1280px, and 1920px WebP and AVIF assets using Node.js sharp, preserving alpha transparency where present, enforcing Core Web Vitals file budgets, and writing zero-CLS <picture>/<img> markup with exact numeric dimensions.
---

# Sharp Responsive WebP & AVIF Image Pipeline Protocol

Never commit multi-megabyte raw PNG outputs straight from FLUX 3 Image, Seedream 5.5, Ideogram 4.6, or GPT-Image-2.6 into `public/`. Whenever adding raster photos, packshots, or hero artwork to a website, execute this deterministic pipeline:

## 1. Verified Sharp Responsive Batch Script (ESM)
Keep original lossless `.png` masters outside `public/` (e.g., `assets-raw/`), and compile responsive breakpoints with `withoutEnlargement: true` and `.rotate()` (auto-applies EXIF orientation and strips metadata bloat):
```js
import { readdirSync, mkdirSync } from 'node:fs';
import { parse, join } from 'node:path';
import sharp from 'sharp';

const IN_DIR = './assets-raw';
const OUT_DIR = './public/images/media';
const WIDTHS = [640, 1280, 1920];
mkdirSync(OUT_DIR, { recursive: true });

for (const file of readdirSync(IN_DIR).filter((f) => /\.(png|jpe?g|webp)$/i.test(f))) {
  const { name } = parse(file);
  const input = join(IN_DIR, file);
  const meta = await sharp(input).metadata();
  const hasAlpha = Boolean(meta.hasAlpha);

  for (const w of WIDTHS) {
    if (meta.width && w > meta.width && w !== WIDTHS[0]) continue;
    const base = sharp(input).rotate().resize({ width: w, withoutEnlargement: true });
    const webpInfo = await base.clone().webp({ quality: hasAlpha ? 90 : 84, alphaQuality: 95, effort: 5 }).toFile(join(OUT_DIR, `${name}-${w}.webp`));
    const avifInfo = await base.clone().avif({ quality: 58, effort: 4 }).toFile(join(OUT_DIR, `${name}-${w}.avif`));
    console.log(`${name}-${w}: ${webpInfo.width}x${webpInfo.height} | WebP ${(webpInfo.size / 1024).toFixed(1)}KB | AVIF ${(avifInfo.size / 1024).toFixed(1)}KB`);
  }
}
```

## 2. File-Weight Budgets by Slot
- **Above-the-fold Hero (`1280px–1920px`):** Target `< 180 KB` WebP (`< 120 KB` AVIF).
- **PDP Square / Card Thumbnail (`640px–1200px`):** Target `< 90 KB` WebP (`< 65 KB` AVIF).
- **Alpha Cutouts (`Seedream 5.5`, `Ideogram 4.6`, `GPT-Image-2.6`, `Bria RMBG`):** Preserve crisp alpha edges (`alphaQuality: 95` WebP or `png({ compressionLevel: 9, palette: false })`); never convert transparent PNGs to JPEG.
- **Charts / Diagrams with Sharp Text:** Use `webp({ quality: 92 })` (never aggressive lossy compression that introduces halo ringing around thin typography).

## 3. Mandatory Zero-CLS `<picture>` / `<img>` Markup Contract
Always emit exact natural pixel `width` and `height` from `sharp` output metadata plus descriptive `alt` text (`10–35` words):
```html
<picture>
  <source type="image/avif" srcset="/images/media/hero-640.avif 640w, /images/media/hero-1280.avif 1280w" sizes="(max-width: 768px) 100vw, 1200px" />
  <source type="image/webp" srcset="/images/media/hero-640.webp 640w, /images/media/hero-1280.webp 1280w" sizes="(max-width: 768px) 100vw, 1200px" />
  <img src="/images/media/hero-1280.webp" width="1280" height="720" alt="Studio stoneware pour-over kettle on travertine counter under 5600K daylight" loading="eager" fetchpriority="high" decoding="async" class="w-full h-auto" />
</picture>
```
- Use `loading="eager" fetchpriority="high"` **ONLY** for the single above-the-fold LCP hero.
- Use `loading="lazy" decoding="async"` for every below-the-fold image.
````

## Example Input

```text
"Optimize the 6 raw FLUX 3 Image product PNGs in ./assets-raw/ into 640px and 1280px WebP/AVIF sets in public/images/products/ and update ProductGallery.astro with zero-CLS <picture> tags."
```

## Expected Output

```text
- Runs sharp batch script encoding 640w + 1280w WebP and AVIF files (cutting 14.2 MB raw PNGs down to 680 KB total across all WebP variants).
- Preserves alpha transparency on the GPT-Image-2.6 studio cutout at alphaQuality: 95.
- Updates ProductGallery.astro with exact numeric width/height attributes, fetchpriority="high" on Hero 01, and loading="lazy" on secondary shots.
```

## Requirements

- Node.js 18+ with `sharp` installed (`npm i -D sharp`)
- Claude Code, Cursor, or Codex

## Known Limits

- Always keep lossless PNG masters outside `public/` if the same frames will later feed Image-to-Video models or 300 DPI print upscaling
- Do not convert crisp vector brand icons into raster WebP—keep icons in native SVG via Skill 30

## Implementation Notes

## Ship fast product galleries and editorial visuals

Pair this skill directly with [Workflow 12: E-Commerce Catalog Packshot and 3D GLB Batch](/workflows/ecommerce-catalog-packshot-batch-pipeline) and [Guide 09: AI Image Craft, Vector SVGs and Brand Design Systems](/guides/ai-image-and-brand-design-systems-guide).
