File size: 3,002 Bytes
8b83582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
Generate synthetic test images in samples/ directory.
These are used by load_test.py to populate the Grafana dashboard.

Run: python scripts/generate_samples.py
"""
import os
import numpy as np
from PIL import Image, ImageDraw

SAMPLES_DIR = os.path.join(os.path.dirname(__file__), "..", "samples")
os.makedirs(SAMPLES_DIR, exist_ok=True)


def save(img: Image.Image, name: str):
    path = os.path.join(SAMPLES_DIR, name)
    img.save(path)
    print(f"  Saved {name}")
    return path


def gradient(w=128, h=128):
    arr = np.zeros((h, w, 3), dtype=np.uint8)
    arr[:, :, 0] = np.linspace(30, 220, w)           # R gradient horizontal
    arr[:, :, 1] = np.linspace(50, 180, h)[:, None]  # G gradient vertical
    arr[:, :, 2] = 120
    return Image.fromarray(arr)


def checkerboard(w=128, h=128, tile=16):
    arr = np.zeros((h, w, 3), dtype=np.uint8)
    for y in range(0, h, tile):
        for x in range(0, w, tile):
            color = 220 if (x // tile + y // tile) % 2 == 0 else 50
            arr[y:y+tile, x:x+tile] = color
    return Image.fromarray(arr)


def portrait(w=96, h=128):
    img = Image.new("RGB", (w, h), (200, 180, 160))
    draw = ImageDraw.Draw(img)
    # sky
    draw.rectangle([0, 0, w, h//3], fill=(100, 150, 220))
    # ground
    draw.rectangle([0, h*2//3, w, h], fill=(80, 130, 80))
    # body
    draw.rectangle([w//3, h//2, w*2//3, h*2//3], fill=(50, 80, 150))
    # head
    draw.ellipse([w//3, h//4, w*2//3, h//2], fill=(220, 180, 140))
    return img


def cityscape(w=160, h=96):
    img = Image.new("RGB", (w, h), (180, 200, 230))
    draw = ImageDraw.Draw(img)
    # sky gradient approximation
    draw.rectangle([0, 0, w, h//2], fill=(100, 140, 200))
    # buildings
    buildings = [
        (10,  60, 30, h,  (80, 80, 100)),
        (35,  40, 60, h,  (100, 90, 110)),
        (65,  50, 85, h,  (70, 70, 90)),
        (90,  30, 115, h, (90, 80, 100)),
        (120, 55, 145, h, (85, 85, 95)),
    ]
    for x0, y0, x1, y1, c in buildings:
        draw.rectangle([x0, y0, x1, y1], fill=c)
        # windows
        for wx in range(x0+4, x1-4, 8):
            for wy in range(y0+6, y1-4, 10):
                draw.rectangle([wx, wy, wx+4, wy+5], fill=(220, 220, 150))
    return img


def nature(w=128, h=128):
    img = Image.new("RGB", (w, h), (100, 160, 220))
    draw = ImageDraw.Draw(img)
    # sky
    draw.rectangle([0, 0, w, h//2], fill=(100, 160, 220))
    # hills
    draw.ellipse([-20, h//2-20, w//2+20, h+10], fill=(60, 120, 60))
    draw.ellipse([w//3, h//2-10, w+20, h+10], fill=(80, 140, 80))
    # sun
    draw.ellipse([w-30, 10, w-10, 30], fill=(255, 220, 50))
    return img


if __name__ == "__main__":
    print("Generating sample images...")
    save(gradient(),      "gradient.png")
    save(checkerboard(),  "checkerboard.png")
    save(portrait(),      "portrait.png")
    save(cityscape(),     "cityscape.png")
    save(nature(),        "nature.png")
    print(f"\nDone — {len(os.listdir(SAMPLES_DIR))} images in samples/")