Skip to content

Commit c3b9002

Browse files
committed
Update thumbnail gen
1 parent 45d5a79 commit c3b9002

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Gallery image workflow
2+
3+
Source images go in `webp-gallery/` (big) and `webp-gallery/thumbs/` (220x220 square thumb). Convention: `snake_case.webp`, big ~850px wide preserving aspect, thumb 220x220 cropped square. Front matter `image:` in `_gallery/<slug>.md` points to the big webp.
4+
5+
## Tools available locally
6+
- `sips` (built-in macOS) — resize, crop with `--cropOffset Y X`
7+
- `cwebp` at `/opt/local/bin/cwebp` — encode webp (use `-q 85`)
8+
- `dwebp` — decode webp to png/jpg when re-cropping an already-converted file
9+
- No `magick`/ImageMagick `convert`, no `ffmpeg`, no Python PIL. Don't reach for them.
10+
11+
## Convert a new gallery image
12+
13+
```bash
14+
SRC=path/to/source.jpg # original from camera/phone
15+
SLUG=keyboard # snake_case
16+
TMP=$(mktemp -d)
17+
sips -s format jpeg --resampleWidth 850 "$SRC" --out "$TMP/big.jpg" >/dev/null
18+
sips -c 220 220 "$SRC" --out "$TMP/thumb.jpg" >/dev/null # default center crop — often bad
19+
cwebp -q 85 "$TMP/big.jpg" -o "webp-gallery/${SLUG}.webp"
20+
cwebp -q 85 "$TMP/thumb.jpg" -o "webp-gallery/thumbs/${SLUG}.webp"
21+
```
22+
23+
## Picking a thumbnail crop (do this — center crop is usually wrong)
24+
25+
`sips -c H W` crops from center by default and produces bad thumbs for off-center subjects. Generate a matrix of candidates and let the user pick:
26+
27+
```bash
28+
SRC=webp-gallery/keyboard.webp # or original jpg
29+
OUT=webp-gallery/thumbs/_picks
30+
mkdir -p "$OUT"; TMP=$(mktemp -d)
31+
dwebp "$SRC" -o "$TMP/src.png" >/dev/null 2>&1 # skip if already png/jpg
32+
# read W H from `sips -g pixelWidth -g pixelHeight`
33+
# pick 3 square sizes (full short-edge, medium, tight) × 3 horizontal positions (left/center/right)
34+
# vary vertical position too if image is tall
35+
for s in 637 500 380; do # square sizes in px
36+
for xp in left center right; do
37+
xmax=$((W - s)); ymax=$((H - s)); y=$((ymax/2))
38+
case $xp in left) x=0;; center) x=$((xmax/2));; right) x=$xmax;; esac
39+
sips -c $s $s --cropOffset $y $x "$TMP/src.png" --out "$TMP/c.png" >/dev/null
40+
sips -z 220 220 "$TMP/c.png" --out "$TMP/r.png" >/dev/null
41+
cwebp -quiet -q 85 "$TMP/r.png" -o "$OUT/${SLUG}_${s}_${xp}.webp"
42+
done
43+
done
44+
open "$OUT" # let user pick in Finder
45+
```
46+
47+
After user picks, copy chosen file to `webp-gallery/thumbs/${SLUG}.webp` and delete `_picks/`.
48+
49+
Note `sips --cropOffset` argument order is **Y X**, not X Y.
50+
51+
## Front matter
52+
Existing convention from `_gallery/*.md`:
53+
```yaml
54+
---
55+
layout: gallery
56+
title: "..."
57+
order: <int>
58+
category: "..."
59+
image: "/webp-gallery/<slug>.webp"
60+
alt: "..."
61+
---
62+
```

0 commit comments

Comments
 (0)