Files
mtusi2026lab5/tests/generate_image_fixtures.py
T

56 lines
1.2 KiB
Python

"""Generate deterministic image fixtures for Track 1 benchmarks."""
import random
from pathlib import Path
from PIL import Image
ROOT = Path(__file__).resolve().parent / "fixtures"
SIZES = {
"small": (640, 480),
"medium": (1600, 1200),
"large": (3000, 2000),
}
def generate_image(name: str, width: int, height: int) -> None:
rng = random.Random(42)
image = Image.new("RGB", (width, height))
pixels = image.load()
for y in range(height):
for x in range(width):
noise = rng.randrange(0, 24)
pixels[x, y] = (
(x * 255 // width + noise) % 256,
(y * 255 // height + noise) % 256,
((x + y) * 255 // (width + height) + noise) % 256,
)
path = ROOT / f"{name}.jpg"
image.save(
path,
format="JPEG",
quality=85,
optimize=True,
)
print(
f"{name}: {width}x{height}, "
f"{path.stat().st_size} bytes"
)
def main() -> None:
ROOT.mkdir(parents=True, exist_ok=True)
for name, (width, height) in SIZES.items():
generate_image(name, width, height)
if __name__ == "__main__":
main()