DevPlace CI / test (push) Failing after 1h5m59s
Pillow 12 renames Image.getdata to get_flattened_data; the award image normaliser and the isslop hue histogram both read pixels that way. The image stack also needs pango, harfbuzz, fontconfig and a base font in the container, so text rendering has glyphs to work with. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
33 lines
986 B
Python
33 lines
986 B
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
from io import BytesIO
|
|
|
|
from PIL import Image
|
|
|
|
|
|
def enforce_rgba_png(file_bytes: bytes) -> bytes:
|
|
img = Image.open(BytesIO(file_bytes)).convert("RGBA")
|
|
width, height = img.size
|
|
if width > 1 and height > 1:
|
|
corner = img.getpixel((0, 0))
|
|
if len(corner) == 4 and corner[3] == 255:
|
|
bg = corner[:3]
|
|
data = img.get_flattened_data()
|
|
cleaned = []
|
|
for pixel in data:
|
|
if pixel[:3] == bg:
|
|
cleaned.append((pixel[0], pixel[1], pixel[2], 0))
|
|
else:
|
|
cleaned.append(pixel)
|
|
img.putdata(cleaned)
|
|
buf = BytesIO()
|
|
img.save(buf, format="PNG")
|
|
return buf.getvalue()
|
|
|
|
|
|
def resize_award_png(source: bytes, size: int) -> bytes:
|
|
img = Image.open(BytesIO(source)).convert("RGBA")
|
|
img = img.resize((size, size), Image.LANCZOS)
|
|
buf = BytesIO()
|
|
img.save(buf, format="PNG")
|
|
return buf.getvalue() |