Image Compression Skill
Compress all images in $ARGUMENTS (or app/assets/images/content/ if no path provided) to WebP format, optimized for SEO performance (target: under 100KB per image).
Process
- Create originals folder - Create
originals/ subfolder inside the target directory and move source files there. Never destroy source files.
- Compress each image (JPG, PNG, GIF) from
originals/ to the parent directory as .webp
- Iterate until all images are under 100KB - check sizes after each pass, re-compress any that exceed the target
- Report results with before/after sizes
- Update references in content files from old extensions to
.webp
File Structure
target-directory/
├── originals/ # High-quality source files preserved here
│ ├── hero.jpg
│ └── feature.png
├── hero.webp # Compressed, web-optimized
└── feature.webp
Iterative Compression Algorithm
IMPORTANT: Keep compressing until ALL images are under 100KB. Check sizes after each pass and re-compress any that exceed the target.
Step 1: Initial pass (q 70)
cwebp -q 70 -resize 1200 0 originals/image.jpg -o image.webp
ls -lh image.webp # Check size
Step 2: If still over 100KB, reduce quality progressively
# Try these in order until under 100KB:
cwebp -q 60 -resize 1200 0 originals/image.jpg -o image.webp
cwebp -q 50 -resize 1200 0 originals/image.jpg -o image.webp
cwebp -q 45 -resize 1200 0 originals/image.jpg -o image.webp
cwebp -q 40 -resize 1200 0 originals/image.jpg -o image.webp
cwebp -q 35 -resize 1200 0 originals/image.jpg -o image.webp
Step 3: For stubborn images, also reduce dimensions
# If q 35 at 1200px is still over 100KB, reduce to 1000px:
cwebp -q 30 -resize 1000 0 originals/image.jpg -o image.webp
cwebp -q 25 -resize 1000 0 originals/image.jpg -o image.webp
Real-World Results (Reference)
From actual compression run on content images:
| Image |
Original |
First Try |
Final |
Settings Used |
| waves.jpg |
198KB |
33KB |
33KB |
q 70, 1200px (1 pass) |
| calendar.jpg |
246KB |
42KB |
42KB |
q 70, 1200px (1 pass) |
| floating.jpg |
230KB |
43KB |
43KB |
q 70, 1200px (1 pass) |
| cash.jpg |
409KB |
88KB |
88KB |
q 70, 1200px (1 pass) |
| knot.jpg |
395KB |
96KB |
96KB |
q 70, 1200px (1 pass) |
| floating-dark.jpg |
414KB |
94KB |
94KB |
q 70, 1200px (1 pass) |
| keyboard2.jpg |
459KB |
102KB |
102KB |
q 70, 1200px (1 pass, acceptable) |
| perpetual.jpg |
565KB |
130KB |
96KB |
q 40, 1200px (3 passes) |
| keyboard.jpg |
718KB |
196KB |
98KB |
q 25, 1000px (5 passes) |
Key Insights
- Most images (under 500KB source) compress fine with default settings (q 70, 1200px)
- Large detailed images (500KB+) often need multiple passes
- Very large images (700KB+) may need both lower quality AND smaller dimensions
- Keyboard/tech photos with fine detail are hardest to compress - expect 4-5 passes
- Soft/blurry images compress much better than sharp detailed ones
After Compression
- Verify ALL files under 100KB:
ls -lh *.webp - re-run compression on any exceeding target
- Update content files referencing old extensions (.jpg, .png) to use .webp
- Test that images render correctly in the application
- Original files remain in
originals/ folder for future reference or re-compression
1---
2name: compress-images
3description: Compress images for web/SEO performance using cwebp. Use when optimizing images for faster page loads, reducing file sizes, or converting JPG/PNG to WebP format.
4argument-hint: "[directory]"
5allowed-tools: Bash(cwebp:*), Bash(ls:*), Bash(mkdir:*), Bash(mv:*)
6metadata:
7 source: https://skillmd.com/skills/aibot88/compress-images
8---
9
10# Image Compression Skill
11
12Compress all images in `$ARGUMENTS` (or `app/assets/images/content/` if no path provided) to WebP format, optimized for SEO performance (target: under 100KB per image).
13
14## Process
15
161. **Create originals folder** - Create `originals/` subfolder inside the target directory and move source files there. Never destroy source files.
172. **Compress each image** (JPG, PNG, GIF) from `originals/` to the parent directory as `.webp`
183. **Iterate until all images are under 100KB** - check sizes after each pass, re-compress any that exceed the target
194. **Report results** with before/after sizes
205. **Update references** in content files from old extensions to `.webp`
21
22## File Structure
23
24```
25target-directory/
26├── originals/ # High-quality source files preserved here
27│ ├── hero.jpg
28│ └── feature.png
29├── hero.webp # Compressed, web-optimized
30└── feature.webp
31```
32
33## Iterative Compression Algorithm
34
35**IMPORTANT:** Keep compressing until ALL images are under 100KB. Check sizes after each pass and re-compress any that exceed the target.
36
37### Step 1: Initial pass (q 70)
38```bash
39cwebp -q 70 -resize 1200 0 originals/image.jpg -o image.webp
40ls -lh image.webp # Check size
41```
42
43### Step 2: If still over 100KB, reduce quality progressively
44```bash
45# Try these in order until under 100KB:
46cwebp -q 60 -resize 1200 0 originals/image.jpg -o image.webp
47cwebp -q 50 -resize 1200 0 originals/image.jpg -o image.webp
48cwebp -q 45 -resize 1200 0 originals/image.jpg -o image.webp
49cwebp -q 40 -resize 1200 0 originals/image.jpg -o image.webp
50cwebp -q 35 -resize 1200 0 originals/image.jpg -o image.webp
51```
52
53### Step 3: For stubborn images, also reduce dimensions
54```bash
55# If q 35 at 1200px is still over 100KB, reduce to 1000px:
56cwebp -q 30 -resize 1000 0 originals/image.jpg -o image.webp
57cwebp -q 25 -resize 1000 0 originals/image.jpg -o image.webp
58```
59
60## Real-World Results (Reference)
61
62From actual compression run on content images:
63
64| Image | Original | First Try | Final | Settings Used |
65|-------|----------|-----------|-------|---------------|
66| waves.jpg | 198KB | 33KB | 33KB | q 70, 1200px (1 pass) |
67| calendar.jpg | 246KB | 42KB | 42KB | q 70, 1200px (1 pass) |
68| floating.jpg | 230KB | 43KB | 43KB | q 70, 1200px (1 pass) |
69| cash.jpg | 409KB | 88KB | 88KB | q 70, 1200px (1 pass) |
70| knot.jpg | 395KB | 96KB | 96KB | q 70, 1200px (1 pass) |
71| floating-dark.jpg | 414KB | 94KB | 94KB | q 70, 1200px (1 pass) |
72| keyboard2.jpg | 459KB | 102KB | 102KB | q 70, 1200px (1 pass, acceptable) |
73| **perpetual.jpg** | 565KB | 130KB | **96KB** | q 40, 1200px (3 passes) |
74| **keyboard.jpg** | 718KB | 196KB | **98KB** | q 25, 1000px (5 passes) |
75
76### Key Insights
77
781. **Most images** (under 500KB source) compress fine with default settings (q 70, 1200px)
792. **Large detailed images** (500KB+) often need multiple passes
803. **Very large images** (700KB+) may need both lower quality AND smaller dimensions
814. **Keyboard/tech photos** with fine detail are hardest to compress - expect 4-5 passes
825. **Soft/blurry images** compress much better than sharp detailed ones
83
84## After Compression
85
861. **Verify ALL files under 100KB**: `ls -lh *.webp` - re-run compression on any exceeding target
872. Update content files referencing old extensions (.jpg, .png) to use .webp
883. Test that images render correctly in the application
894. Original files remain in `originals/` folder for future reference or re-compression