Files
phtotest/tools/make_test_photos.py
DESKTOP-PUHFO60\dsx2016 6cf42d56a7 Fix photo stripes and keep GIF playback off the UI thread.
Use cover/stretch display, solid sample assets, core0 GIF decode without blocking touch, and always-commit project rule.

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

72 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Generate 320x240 JPG/PNG/GIF samples into assets/photos (solid bg, no stripes)."""
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)
# Solid panel only — no horizontal stripe decoration
d.rounded_rectangle((20, 36, W - 20, H - 36), radius=12, fill=bg, outline=accent, width=3)
d.text((36, 70), title, fill=(234, 240, 246), font=font(36))
d.text((36, 130), subtitle, fill=(160, 175, 190), font=font(20))
d.text((36, 170), "CYD ALBUM TEST", fill=accent, font=font(16))
if fmt == "JPEG":
im.save(path, "JPEG", quality=92)
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((28, 12, 18), (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=(160, 175, 190), font=font(18))
x = 20 + i * 40
d.rounded_rectangle((x, 120, x + 80, 180), radius=8, fill=(255, 200, 40))
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()