docs/skills/image-handling/SKILL.md
Image handling for Claude API constraints (5MB max, 8000px max dimension). Use when working with images, screenshots, or MCP browser tools.
npx skillsauth add megalithic/dotfiles image-handlingInstall 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.
CRITICAL: All images must fit within Anthropic's API constraints:
Images exceeding these limits will cause API errors.
Working with an image?
│
├─▶ User provided image path?
│ └─▶ resize-image --check <path>
│ ├─▶ "ok" → Use as-is
│ └─▶ "needs-resize" → resize-image <path>
│
├─▶ Taking browser screenshot?
│ └─▶ fullPage: true?
│ ├─▶ YES → DANGER! May exceed limits
│ │ └─▶ Save to file, then check/resize
│ └─▶ NO → Usually safe (viewport only)
│
├─▶ Multiple images?
│ └─▶ Check each: resize-image --check
│
└─▶ Unsure about image?
└─▶ resize-image --info <path>
└─▶ Shows dimensions and size
Image exceeds API limits?
│
├─▶ Dimension > 8000px?
│ └─▶ resize-image <image>
│ └─▶ Auto-scales to fit 8000px max
│
├─▶ File size > 5MB but dimensions OK?
│ └─▶ resize-image --quality 70 <image>
│ └─▶ Reduces quality for smaller file
│
├─▶ Both dimension AND size issues?
│ └─▶ resize-image --quality 60 --max-dimension 4000 <image>
│
└─▶ Still too large after resize?
└─▶ Lower quality further: --quality 40
└─▶ Or reduce max-dimension: --max-dimension 2000
Location: ~/bin/resize-image
resize-image --info <image> # Show dimensions and size
resize-image --check <image> # Quick check: "needs-resize" or "ok"
resize-image <image> # Resize if needed (creates <name>-resized.<ext>)
resize-image <image> <output> # Resize to specific output path
resize-image --quality 70 <image> # Lower quality for more compression
Always check before processing:
# 1. Check if resize is needed
resize-image --check /path/to/image.png
# 2. If output is "needs-resize", resize it
resize-image /path/to/image.png
# 3. Use the resized version
# Original: /path/to/image.png
# Resized: /path/to/image-resized.png
| Flag | Purpose |
|------|---------|
| --info | Show dimensions, file size, and whether it exceeds limits |
| --check | Quick check, outputs "ok" or "needs-resize" |
| --quality N | JPEG/WebP quality 1-100 (default: 85) |
| --max-dimension N | Override max dimension (default: 8000) |
| --max-size N | Override max file size in bytes (default: 5MB) |
When using chrome-devtools MCP for screenshots:
// AVOID: Full-page screenshots of long pages
chrome-devtools_take_screenshot({ fullPage: true }) // May exceed limits!
// PREFER: Viewport-only screenshots
chrome-devtools_take_screenshot() // Just visible area
// PREFER: Element screenshots for specific content
chrome-devtools_take_screenshot({ uid: "element-id" })
// SAFE: Save to file and resize before reading
chrome-devtools_take_screenshot({ filePath: "/tmp/screenshot.png" })
// Then: resize-image --check /tmp/screenshot.png
Same principles apply:
// AVOID
mcp__playwright__screenshot({ fullPage: true })
// PREFER
mcp__playwright__screenshot() // Viewport only
mcp__playwright__screenshot({ element: "selector" })
When saving screenshots to disk via MCP:
# 1. Take screenshot to file
# (via MCP tool with filePath parameter)
# 2. Check if resize needed
resize-image --check /tmp/screenshot.png
# 3. If "needs-resize", resize before reading
resize-image /tmp/screenshot.png
# 4. Read the resized version
# /tmp/screenshot-resized.png
The resize-image script handles:
# For screenshots with text (keep quality high)
resize-image --quality 90 screenshot.png
# For photos (can use lower quality)
resize-image --quality 70 photo.jpg
# For very large images, combine dimension + quality reduction
resize-image --quality 60 --max-dimension 4000 huge-image.png
# 1. Check the image
resize-image --check /path/from/user.png
# 2. If "needs-resize"
resize-image /path/from/user.png
# Use: /path/from/user-resized.png
# 3. If "ok"
# Use original: /path/from/user.png
# 1. Take viewport screenshot (via MCP)
# Saved to: /tmp/debug-screenshot.png
# 2. Always check before processing
resize-image --check /tmp/debug-screenshot.png
# 3. Resize if needed, then read
# Check all images in a directory
for img in /path/to/images/*; do
result=$(resize-image --check "$img")
if [ "$result" = "needs-resize" ]; then
resize-image "$img"
fi
done
# BAD: Reading image without checking size
cat /path/to/huge-image.png | base64 # May fail API limits
# GOOD: Check and resize first
resize-image --check /path/to/image.png
resize-image /path/to/image.png # If needed
If you see errors like:
Solution: Use resize-image before retrying.
The script uses ImageMagick under the hood:
# Check dimensions
identify image.png
# Resize with ImageMagick
convert image.png -resize 8000x8000\> -quality 85 output.png
# Show help
resize-image --help
# Show info about any image
resize-image --info /path/to/image.png
# Check if ImageMagick is available
which convert identify
# Current known limits (may change):
# - Max file size: 5MB (5242880 bytes)
# - Max dimension: 8000px (either width or height)
# - Supported formats: PNG, JPEG, WebP, GIF
# Check file size
ls -la image.png
stat -f%z image.png # macOS
# Check ImageMagick is installed
which convert || echo "ImageMagick not installed!"
# If missing, add to home/packages.nix:
# pkgs.imagemagick
# Check what happened
resize-image --info original.png
resize-image --info original-resized.png
# Force more aggressive compression
resize-image --quality 50 --max-dimension 2000 original.png
# Double-check file size
ls -la image-resized.png
# Try converting to JPEG (usually smaller than PNG)
convert image.png -quality 80 image.jpg
resize-image --check image.jpg
# Check file exists and is readable
ls -la /path/to/image.png
# Check file type
file /path/to/image.png
# ImageMagick can identify format issues
identify /path/to/image.png
testing
Apply Strunk's timeless writing rules to ANY prose humans will read - documentation, commit messages, error messages, explanations, reports, or UI text. Makes your writing clearer, stronger, and more professional.
tools
Web search using DuckDuckGo (free, unlimited). Falls back to pi-web-access extension for content extraction.
tools
Interact with web pages using agent-browser CLI. MUST run 'browser connect 9222' FIRST to use existing browser with authenticated sessions.
tools
Remote control tmux sessions for interactive CLIs (python, gdb, etc.) by sending keystrokes and scraping pane output.