Files
phtotest/tools/make_test_photos.py
DESKTOP-PUHFO60\dsx2016 99618a46b0 Add CYD photo album with jpg/png/gif viewer and sample assets.
Ship TF-card album UI, half-res decode canvas, prebuilt firmware, and documented flash/upload workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 18:07:56 +08:00

76 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Generate 320x240 JPG/PNG/GIF samples into assets/photos."""
from __future__ import annotations
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "assets" / "photos"
W, H = 320, 240
def font(size: int = 28) -> ImageFont.ImageFont:
for name in (
r"C:\Windows\Fonts\msyh.ttc",
r"C:\Windows\Fonts\arial.ttf",
r"C:\Windows\Fonts\consola.ttf",
):
try:
return ImageFont.truetype(name, size)
except OSError:
pass
return ImageFont.load_default()
def card(bg, accent, title: str, subtitle: str, path: Path, fmt: str) -> None:
im = Image.new("RGB", (W, H), bg)
d = ImageDraw.Draw(im)
for i in range(0, H, 12):
c = tuple(max(0, min(255, v + (i % 24) - 12)) for v in accent)
d.rectangle((0, i, W, i + 6), fill=c)
d.rectangle((16, 40, W - 16, H - 40), fill=bg)
d.rectangle((16, 40, W - 16, H - 40), outline=accent, width=3)
d.text((28, 70), title, fill=(234, 240, 246), font=font(36))
d.text((28, 130), subtitle, fill=(122, 139, 156), font=font(20))
d.text((28, 170), "CYD ALBUM TEST", fill=accent, font=font(16))
if fmt == "JPEG":
im.save(path, "JPEG", quality=90)
else:
im.save(path, "PNG")
print(f"wrote {path} ({path.stat().st_size} bytes)")
def main() -> None:
OUT.mkdir(parents=True, exist_ok=True)
card((10, 16, 22), (79, 195, 247), "01 JPG", "tap left / right", OUT / "01_blue.jpg", "JPEG")
card((20, 12, 28), (232, 93, 76), "02 JPG", "red sample", OUT / "02_red.jpg", "JPEG")
card((8, 28, 20), (61, 220, 151), "03 PNG", "green sample", OUT / "03_green.png", "PNG")
frames = []
for i in range(6):
im = Image.new("RGB", (W, H), (10, 16, 22))
d = ImageDraw.Draw(im)
d.text((24, 24), "04 GIF", fill=(234, 240, 246), font=font(32))
d.text((24, 70), "animated", fill=(122, 139, 156), font=font(18))
x = 20 + i * 40
d.rectangle((x, 120, x + 80, 180), fill=(255, 200, 40))
d.rectangle((20, 200, 300, 210), fill=(36, 49, 64))
frames.append(im)
gif_path = OUT / "04_bounce.gif"
frames[0].save(
gif_path,
save_all=True,
append_images=frames[1:],
duration=120,
loop=0,
optimize=False,
)
print(f"wrote {gif_path} ({gif_path.stat().st_size} bytes)")
print("DONE")
if __name__ == "__main__":
main()