Download scripts/make_overlays.py from Warren-wzw/PCB-Layout: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/datasets/Warren-wzw/PCB-Layout/resolve/main/scripts/make_overlays.py
- Command line
-
hf download hf://datasets/Warren-wzw/PCB-Layout/scripts/make_overlays.py
-
curl -L -o make_overlays.py https://huggingface.co/datasets/Warren-wzw/PCB-Layout/resolve/main/scripts/make_overlays.py
1.53 kB
| """Render alignment animations without registration, cropping, or warping.""" | |
| from pathlib import Path | |
| import re | |
| from PIL import Image | |
| ROOT = Path(__file__).resolve().parents[1] | |
| samples = re.findall(r'src="assets/preview/PCB/([^\"]+)"', (ROOT / "README.md").read_text()) | |
| out = ROOT / "assets/preview/Overlay" | |
| out.mkdir(parents=True, exist_ok=True) | |
| for name in samples: | |
| with Image.open(ROOT / "assets/preview/PCB" / name) as image: | |
| pcb = image.convert("RGB") | |
| with Image.open(ROOT / "assets/preview/Layout" / name) as image: | |
| layout = image.convert("RGB") | |
| assert pcb.size == layout.size, f"Size mismatch: {name}" | |
| # Apply identical display downsampling; preserve the supplied correspondence. | |
| pcb.thumbnail((640, 640), Image.Resampling.LANCZOS) | |
| layout = layout.resize(pcb.size, Image.Resampling.LANCZOS) | |
| frames = [Image.blend(pcb, layout, alpha) for alpha in (0, 0.5, 1, 0.5)] | |
| # A shared palette prevents unrelated colors from flickering between frames. | |
| atlas = Image.new("RGB", (pcb.width * 3, pcb.height)) | |
| for i, frame in enumerate(frames[:3]): | |
| atlas.paste(frame, (i * pcb.width, 0)) | |
| palette = atlas.quantize(colors=256) | |
| frames = [frame.quantize(palette=palette, dither=Image.Dither.NONE) for frame in frames] | |
| frames[0].save(out / f"{Path(name).stem}.gif", save_all=True, | |
| append_images=frames[1:], duration=[1000, 700, 1000, 700], | |
| loop=0, disposal=2, optimize=False) | |
| print(f"Rendered {len(samples)} animated overlays.") | |