| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | import numpy as np |
| 7 | from PIL import Image |
| 8 | |
| 9 | def picture(w, h, seed): |
| 10 | rng = np.random.default_rng(seed) |
| 11 | y, x = np.mgrid[0:h, 0:w] |
| 12 | r = (x * 255 // max(w - 1, 1)) % 256 |
| 13 | g = (y * 255 // max(h - 1, 1)) % 256 |
| 14 | b = ((x ^ y) * 5) % 256 |
| 15 | img = np.stack([r, g, b], -1).astype(np.int32) |
| 16 | img += rng.integers(-24, 25, img.shape) |
| 17 | img[h // 3: h // 3 + 6, w // 4: w // 4 + 9] = [250, 10, 20] |
| 18 | return Image.fromarray(np.clip(img, 0, 255).astype(np.uint8), "RGB") |
| 19 | |
| 20 | SUB = {"420": 2, "422": 1, "444": 0} |
| 21 | jobs = [] |
| 22 | for name, sub in SUB.items(): |
| 23 | jobs.append((f"prog{name}", dict(progressive=True, subsampling=sub, quality=85), (64, 48))) |
| 24 | jobs.append((f"rst{name}", dict(restart_marker_blocks=2, subsampling=sub, quality=80), (64, 48))) |
| 25 | jobs.append((f"progrst{name}", dict(progressive=True, restart_marker_blocks=3, subsampling=sub, quality=70), (53, 37))) |
| 26 | jobs.append((f"odd{name}", dict(subsampling=sub, quality=90, optimize=True), (51, 35))) |
| 27 | jobs.append(("basegray", dict(quality=75), (40, 24), "L")) |
| 28 | jobs.append(("proggray", dict(progressive=True, quality=85), (64, 48), "L")) |
| 29 | jobs.append(("rstgray", dict(restart_marker_blocks=2, quality=80), (61, 45), "L")) |
| 30 | for i, job in enumerate(jobs): |
| 31 | name, kw, (w, h) = job[:3] |
| 32 | img = picture(w, h, i + 1) |
| 33 | if len(job) > 3: |
| 34 | img = img.convert(job[3]) |
| 35 | img.save(f"{name}.jpg", "JPEG", **kw) |