Skip to content
FramesField
SKILL.md Developer / Local Tooling SKILL.md
Verified Nov 30, 2026

Sharp WebP, AVIF and Responsive Image Skill

How to install this SKILL.md

Install into .claude/skills/, .cursor/skills/, or .agents/skills/ so your coding agent automatically compiles lightweight responsive WebP/AVIF sets with CLS = 0 markup whenever you add images.

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.

Compatible agent hosts
Claude Code Cursor Codex
Target tool: Node.js Sharp / WebP & AVIF · License: MIT
  1. STEP 01
    Install the Sharp Image Pipeline skill

    Choose Claude Code, Cursor, or Codex below to install SKILL.md from /raw/skills/.

  2. STEP 02
    Point your agent at raw AI PNG exports

    Ask it to process ./raw-assets/ into responsive 640px, 1280px, and 1920px WebP + AVIF deliverables.

  3. STEP 03
    Get <picture> markup with exact dimensions

    Auto-emits width, height, srcset, sizes, and fetchpriority so Core Web Vitals stay green (CLS = 0).

1. Install for your tool

Pick the app you use below for the exact verified command or config—zero manual guessing.

Direct raw file (SKILL.md) ↓
Claude Code (.claude/skills/) bash
Installs into .claude/skills/sharp-responsive-images/SKILL.md for automated responsive WebP/AVIF encoding.
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

2. Inspect or download the full SKILL.md file

This is the exact raw file served at /raw/skills/sharp-responsive-webp-image-pipeline-skill.

Sharp WebP, AVIF and Responsive Image Skill SKILL.md
---
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.

3. Test it right away (sample prompt & result)

Sample prompt / input
"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."
What happens when it runs
- 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.

What you need & known limits

Requirements

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

Watch out for

  • 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

Frequently Asked Questions

Why encode both AVIF and WebP instead of only WebP?
AVIF typically cuts file weight another 25–40% compared to WebP on photographic gradients (improving mobile LCP), while WebP serves as an instant universal fallback inside a single standard HTML <picture> block.
Does calling sharp().rotate() without arguments rotate my images sideways?
No. Calling .rotate() with no angle reads the image's EXIF orientation header, applies the proper upright rotation to pixel data, and strips EXIF bloat so photos never display upside-down across browsers.
Use this page in AI tools or notes
raw .md