Files
mtusi2026lab5/student-tests/pictures.py
T
ArtyomandClaude Opus 5.5 540fcb35ba Carry over the lab 4 solution
Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6 and RustFS configuration, migrations, hooks, evidence and
scenario scripts and the CI job from the lab 4 solution commit d2744bc,
merge the lab 4 Makefile targets into the lab 5 skeleton Makefile
without touching its targets, and append the lab 4 solution variables
to the skeleton .env.example. The package and the application follow
the contract version 1.5.0, and the image and the throwaway test
containers are tagged lab5 so they do not collide with a lab 4 stand on
the same host.

This is the starting point of the lab 5 cycle: lint, own tests and the
offline skeleton check pass before any lab 5 change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 00:34:03 +03:00

36 lines
1.1 KiB
Python

import struct
import zlib
from io import BytesIO
from pathlib import Path
from PIL import Image
SAMPLE = (Path(__file__).resolve().parents[1] / "tests" / "fixtures" / "sample.png").read_bytes()
SIGNATURE = b"\x89PNG\r\n\x1a\n"
def chunk(kind: bytes, data: bytes) -> bytes:
crc = zlib.crc32(kind + data)
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", crc)
def png(width: int, height: int, *, size: int | None = None, rows: bool = True) -> bytes:
header = struct.pack(">IIBBBBB", width, height, 1, 0, 0, 0, 0)
raw = (b"\x00" * (1 + (width + 7) // 8)) * height if rows else b"\x00"
head = SIGNATURE + chunk(b"IHDR", header) + chunk(b"IDAT", zlib.compress(raw, 9))
tail = chunk(b"IEND", b"")
if size is not None:
head += chunk(b"prVt", b"\x00" * (size - len(head) - len(tail) - 12))
return head + tail
def encoded(kind: str, width: int = 640, height: int = 480) -> bytes:
buffer = BytesIO()
Image.effect_noise((width, height), 64).convert("RGB").save(buffer, kind)
return buffer.getvalue()
JPEG = encoded("JPEG")
GIF = encoded("GIF")
WEBP = encoded("WEBP")