heymegabyte/agent-skills / 12-media-orchestration
media-orchestration
VerifiedSection-by-section media planning and generation. Image generation (GPT Image 2 primary, built-in fallback), logo/icon generation (Ideogram v3 → favicon set), video generation (Veo 3.1), social preview images (OG 1200x630 + AI search optimization), stock photo curation (Pexels, Pixabay), critique/remix loops (max 3 rounds), asset compression pipeline, and media performance budgets.
| File | Kind | Size |
|---|---|---|
| 30-ideogram-methods.md | markdown | 16.0 KB |
| SKILL.md | skill md | 6.7 KB |
| build-breaking-rules.md | markdown | 48.2 KB |
| compression-pipeline.md | markdown | 3.8 KB |
| image-optimization.md | markdown | 6.6 KB |
| image-profiling.md | markdown | 3.2 KB |
| lightbox-classifier.md | markdown | 10.0 KB |
| media-prompts.md | markdown | 3.8 KB |
| notebooklm-pipeline.md | markdown | 22.1 KB |
| og-card-pipeline.md | markdown | 19.5 KB |
| og-image-generation.md | markdown | 8.5 KB |
| social-brand-hex.md | markdown | 3.8 KB |
| technical-diagramming.md | markdown | 4.4 KB |
| templates/PROMPTS.md | markdown | 10.0 KB |
image-optimization.md
View on GitHub---
name: "Image Optimization Pipeline"
description: "Sharp for server-side image processing: resize, WebP/AVIF conversion, responsive srcset generation (320w-1920w), blur placeholders. Pipeline integrates with Uppy uploads via post-upload Worker, stores optimized variants in R2. Cloudflare Image Resizing as on-demand alternative."
updated: "2026-04-23"
---
# Image Optimization Pipeline
## Sharp Processing Worker
```typescript
// src/workers/image-processor.ts
import sharp from 'sharp';
interface ImageVariant {
width: number;
suffix: string;
}
const VARIANTS: readonly ImageVariant[] = [
{ width: 320, suffix: '320w' },
{ width: 640, suffix: '640w' },
{ width: 1280, suffix: '1280w' },
{ width: 1920, suffix: '1920w' },
] as const;
const FORMATS = ['webp', 'avif'] as const;
interface ProcessedImage {
key: string;
format: string;
width: number;
size: number;
}
async function processImage(
env: Env,
originalKey: string,
buffer: ArrayBuffer,
): Promise<{ variants: ProcessedImage[]; blurDataUrl: string; dominantColor: string }> {
const image = sharp(Buffer.from(buffer));
const metadata = await image.metadata();
const variants: ProcessedImage[] = [];
// Generate all size × format combinations
for (const variant of VARIANTS) {
if (variant.width > (metadata.width ?? 9999)) continue; // Skip upscaling
for (const format of FORMATS) {
const quality = format === 'webp' ? 80 : 70; // Visually lossless
const processed = await sharp(Buffer.from(buffer))
.resize(variant.width, undefined, { fit: 'inside', withoutEnlargement: true })
.toFormat(format, { quality })
.toBuffer();
const key = originalKey.replace(/\.[^.]+$/, `-${variant.suffix}.${format}`);
await env.R2.put(key, processed, {
httpMetadata: { contentType: `image/${format}` },
customMetadata: { originalKey, width: String(variant.width), format },
});
variants.push({ key, format, width: variant.width, size: processed.byteLength });
}
}
// Blur placeholder (tiny 20px base64)
const blurBuffer = await sharp(Buffer.from(buffer))
.resize(20, undefined, { fit: 'inside' })
.blur(10)
.webp({ quality: 20 })
.toBuffer();
const blurDataUrl = `data:image/webp;base64,${blurBuffer.toString('base64')}`;
// Dominant color extraction
const { dominant } = await sharp(Buffer.from(buffer)).stats();
const dominantColor = `rgb(${dominant.r},${dominant.g},${dominant.b})`;
return { variants, blurDataUrl, dominantColor };
}
```
## Post-Upload Queue Handler
```typescript
// src/queues/image-queue.ts
import { Hono } from 'hono';
interface ImageMessage {
key: string;
contentType: string;
}
export default {
async queue(batch: MessageBatch<ImageMessage>, env: Env): Promise<void> {
for (const message of batch.messages) {
const { key, contentType } = message.body;
if (!contentType.startsWith('image/')) {
message.ack();
continue;
}
const object = await env.R2.get(key);
if (!object) { message.ack(); continue; }
const buffer = await object.arrayBuffer();
const result = await processImage(env, key, buffer);
// Store metadata in D1
await env.DB.prepare(
`UPDATE files SET variants = ?, blur_data_url = ?, dominant_color = ?, processed = 1 WHERE key = ?`
).bind(JSON.stringify(result.variants), result.blurDataUrl, result.dominantColor, key).run();
message.ack();
}
},
};
```
## Responsive Image Component (Angular)
```typescript
// responsive-image.component.ts
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector: 'app-responsive-image',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<picture>
<source
type="image/avif"
[srcset]="avifSrcset"
[sizes]="sizes" />
<source
type="image/webp"
[srcset]="webpSrcset"
[sizes]="sizes" />
<img
[src]="fallbackSrc"
[alt]="alt"
[width]="width"
[height]="height"
[loading]="eager ? 'eager' : 'lazy'"
decoding="async"
[style.background-color]="dominantColor"
[style.background-image]="blurDataUrl ? 'url(' + blurDataUrl + ')' : ''"
style="background-size: cover" />
</picture>
`,
})
export class ResponsiveImageComponent {
@Input({ required: true }) baseUrl!: string;
@Input({ required: true }) alt!: string;
@Input() width = 0;
@Input() height = 0;
@Input() eager = false;
@Input() sizes = '(max-width: 640px) 100vw, (max-width: 1280px) 50vw, 33vw';
@Input() blurDataUrl = '';
@Input() dominantColor = '#060610';
get webpSrcset(): string {
return [320, 640, 1280, 1920].map((w) => `${this.variantUrl(w, 'webp')} ${w}w`).join(', ');
}
get avifSrcset(): string {
return [320, 640, 1280, 1920].map((w) => `${this.variantUrl(w, 'avif')} ${w}w`).join(', ');
}
get fallbackSrc(): string { return this.variantUrl(1280, 'webp'); }
private variantUrl(width: number, format: string): string {
return this.baseUrl.replace(/\.[^.]+$/, `-${width}w.${format}`);
}
}
```
## Cloudflare Image Resizing (On-Demand Alternative)
```typescript
// No pre-generation needed — CF resizes on first request, caches at edge
// Requires CF Pro+ plan with Image Resizing enabled
function cfImageUrl(originalUrl: string, width: number, format: 'webp' | 'avif' = 'webp'): string {
return `/cdn-cgi/image/width=${width},format=${format},quality=80/${originalUrl}`;
}
// Usage in HTML: srcset with CF transform URLs
// <img srcset="/cdn-cgi/image/width=320,format=webp/hero.jpg 320w, /cdn-cgi/image/width=640,format=webp/hero.jpg 640w" />
```
## Uppy Integration (trigger processing after upload)
```typescript
// In upload success handler, queue image for processing
uploads.post('/presign', zValidator('json', uploadSchema), async (c) => {
// ... presign logic ...
// After successful upload confirmation:
await c.env.IMAGE_QUEUE.send({ key, contentType });
return c.json({ key, publicUrl });
});
```
## wrangler.toml Bindings
```toml
[[queues.producers]]
queue = "image-processing"
binding = "IMAGE_QUEUE"
[[queues.consumers]]
queue = "image-processing"
max_batch_size = 5
max_retries = 3
```
## Quality Settings
- **WebP** — quality 80 (SSIM ~0.98, visually lossless)
- **AVIF** — quality 70 (same perceptual quality, 30-50% smaller than WebP)
- Never upscale
- Skip variants wider than original
- **Asset budgets** — single image ≤200KB · total page images ≤500KB · hero ≤150KB (canonical: `_kernel/standards.md#budget`)
- **Hero** — eager + preload
- **Everything else** — lazy, `decoding=async`
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |