skills/optimize-images/SKILL.md
This skill should be used when the user asks to "optimize images", "compress images", "reduce image file size", "make images smaller", "optimize PNGs", "optimize JPEGs", "speed up website images", "reduce bundle size images", or needs help with image compression for web projects. Provides workflows and scripts for batch image optimization using sharp.
npx skillsauth add b-open-io/gemskills optimize-imagesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Optimize images for web performance using modern tools. This skill provides scripts and workflows for compressing PNG and JPEG images while maintaining visual quality.
Sharp is the fastest Node.js image processing library, built on libvips. Use it for all image optimization tasks.
bun add -d sharp
# or
npm install -D sharp
Before optimization, measure baseline metrics:
# Total size and count
du -sh public/images/
find public/images -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" \) | wc -l
# Size by format
find public/images -name "*.png" -exec du -ch {} + | tail -1
find public/images \( -name "*.jpg" -o -name "*.jpeg" \) -exec du -ch {} + | tail -1
# Top 20 largest files
find public/images -type f \( -name "*.png" -o -name "*.jpg" \) -exec ls -la {} \; | \
awk '{print $5, $9}' | sort -rn | head -20 | \
awk '{printf "%6.1fMB %s\n", $1/1048576, $2}'
Always test optimization settings on one image first:
bun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.ts --file=public/images/largest-image.png --dry-run
After verifying settings work well:
bun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.ts
# Compare before/after
du -sh public/images/
# Visually inspect optimized images
# Run production build
bun run build
Sharp's PNG encoder with palette mode for maximum compression:
sharp(filePath)
.png({
quality: 80, // 1-100, lower = smaller
compressionLevel: 9, // 0-9, higher = more compression
adaptiveFiltering: true,
palette: true, // Use palette for smaller files
})
.toBuffer();
Recommended settings:
Sharp with mozjpeg for superior compression:
sharp(filePath)
.jpeg({
quality: 80, // 1-100, lower = smaller
mozjpeg: true, // Use mozjpeg encoder
})
.toBuffer();
Recommended settings:
Copy scripts/optimize-images.ts to the project's scripts directory. The script:
# Dry run (see what would happen)
bun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.ts --dry-run
# Test single file
bun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.ts --file=path/to/image.png
# Full optimization
bun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.ts
Typical results for unoptimized web images:
| Image Type | Typical Savings | |------------|-----------------| | Screenshots (PNG) | 40-60% | | Photos (JPEG) | 20-40% | | Watercolors (PNG) | 30-50% | | Icons (PNG) | 10-30% |
Next.js provides automatic image optimization via next/image. However, optimizing source images still helps:
Keep source images optimized even when using next/image.
Add to .husky/pre-commit or git hooks:
# Warn if large images are being committed
find public/images -name "*.png" -size +500k -exec echo "Warning: Large image: {}" \;
Add to build pipeline:
# Fail if images exceed threshold
MAX_SIZE=79 # MB
CURRENT=$(du -sm public/images | cut -f1)
if [ "$CURRENT" -gt "$MAX_SIZE" ]; then
echo "Error: Images exceed ${MAX_SIZE}MB (currently ${CURRENT}MB)"
exit 1
fi
Increase quality settings:
quality to 85-90quality to 85-90Ensure palette: true handles transparency correctly. For complex transparency, use:
.png({ quality: 85, palette: false })
On macOS, ensure libvips is available:
brew install vips
Or let sharp download pre-built binaries:
npm rebuild sharp
references/optimization-guide.md - Detailed compression algorithms and format comparisonreferences/sharp-api.md - Complete sharp API reference for imagesscripts/optimize-images.ts - Production-ready optimization scriptDo not read optimized images back into context. The script outputs a summary table with file sizes, savings percentages, and totals. Ask the user to visually inspect results if quality verification is needed. Even optimized images can be large enough to fill the context window when processing many files.
bun add -d sharpdu -sh public/images/bun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.ts --dry-runbun run --cwd ${CLAUDE_PLUGIN_ROOT} ${CLAUDE_PLUGIN_ROOT}/skills/optimize-images/scripts/optimize-images.tsdevelopment
This skill should be used when the user asks to "plan a workflow", "diagram an agent system", "visualize an architecture", "map out a pipeline", "create a flow diagram", "draw agent connections", "design a multi-agent system", "show how agents interact", "make a system diagram", "visualize a data pipeline", "map out a process", "diagram my workflow", "create an architecture diagram", "plan agent orchestration", "brainstorm a system design", "show the flow between components", "interactive workflow diagram", "workflow canvas", "visual-planner", "open in tldraw", or "plan this project visually". Produces tldraw .tldr diagrams natively — the standard infinite canvas format. Includes a thin playground wrapper with planning-specific UI (phase controls, agent assignment, KPI bar, agent callback bridge) and an "Open in tldraw" button for standalone editing.
data-ai
This skill should be used when the user asks to "upscale an image", "increase image resolution", "make image bigger", "enlarge image", or "enhance image resolution". Requires Vertex AI credentials.
data-ai
This skill should be used when the user asks to "create team photo", "generate group portrait", "make team banner", "team image in any style", "group shot with multiple people", or needs a composite image featuring multiple team members arranged together in any art style.
development
This skill should be used when the user asks to "add a new style", "create a style", "add an art style", "new aesthetic", "custom style", "make a style for", or needs to add a new art style to the gemskills style library. Guides the complete workflow from defining the style to generating and optimizing the reference tile.