PulseCanvas / app · pulsecanvas.ai / assets / app-store / shared / prepare-callouts.py
| 1 | """Crop complete, real controls; marketing frames supply equal padding on all sides. |
| 2 | |
| 3 | Usage: python3 prepare-callouts.py /absolute/native-capture-folder |
| 4 | Never modifies source screenshots. Crops remain alongside captures, outside Git. |
| 5 | """ |
| 6 | from pathlib import Path |
| 7 | from PIL import Image, ImageChops |
| 8 | import json, sys |
| 9 | root = Path(sys.argv[1]) |
| 10 | # Bounds encompass whole controls; trim only surrounding flat panel background. |
| 11 | regions = { |
| 12 | 'iphone': { |
| 13 | 'studio': (30, 2136, 822, 2604), |
| 14 | 'style': (72, 866, 1134, 1296), |
| 15 | 'radio': (48, 1480, 1158, 2210), |
| 16 | 'export': (72, 661, 1134, 925), |
| 17 | }, |
| 18 | 'ipad': { |
| 19 | 'studio': (24, 1738, 2176, 2055), |
| 20 | 'style': (844, 810, 1908, 1306), |
| 21 | 'radio': (24, 1790, 2728, 1986), |
| 22 | 'export': (844, 640, 1908, 866), |
| 23 | }, |
| 24 | 'duo-inner': { |
| 25 | 'studio': (40, 1520, 2456, 1992), |
| 26 | 'style': (518, 710, 2337, 1415), |
| 27 | 'radio': (36, 1595, 2817, 1895), |
| 28 | 'export': (518, 510, 2337, 775), |
| 29 | }, |
| 30 | } |
| 31 | manifest = [] |
| 32 | for prefix, entries in regions.items(): |
| 33 | for kind, bounds in entries.items(): |
| 34 | source = root / f'{prefix}-{kind}.png' |
| 35 | if not source.exists(): continue |
| 36 | im = Image.open(source).convert('RGB') |
| 37 | color = (31, 25, 36) # Native MobileTheme panel background, including all padding. |
| 38 | crop = im.crop(bounds) |
| 39 | # Native timeline cards include borders, whereas other content can be tightly trimmed. |
| 40 | diff = ImageChops.difference(crop, Image.new('RGB', crop.size, color)) |
| 41 | mask = diff.convert('L').point(lambda p: 255 if p > 8 else 0) |
| 42 | tight = mask.getbbox() |
| 43 | assert tight, f'Blank callout: {source.name}' |
| 44 | crop = crop.crop(tight) |
| 45 | path = root / f'{prefix}-callout-{kind}.png' |
| 46 | crop.save(path) |
| 47 | manifest.append({'prefix': prefix, 'kind': kind, 'file': path.name, |
| 48 | 'background': '#%02x%02x%02x' % color, |
| 49 | 'width': crop.width, 'height': crop.height, |
| 50 | 'sourceBounds': bounds, 'trim': tight}) |
| 51 | (root/'callout-manifest.json').write_text(json.dumps(manifest, indent=2)+'\n') |
| 52 | print(json.dumps(manifest, indent=2)) |