Handle invalid random photos before device writes and trace selections

This commit is contained in:
Pigway
2026-10-06 08:47:03 +08:00
parent 59345f12a7
commit 0a5b859ca0
8 changed files with 231 additions and 21 deletions
+3 -2
View File
@@ -11,7 +11,8 @@ from pigway_frame_flow.errors import ErrorCode as E
from pigway_frame_flow.errors import FlowError
from pigway_frame_flow.storage.database import now_iso
Image.MAX_IMAGE_PIXELS = 25_000_000
MAX_IMAGE_PIXELS = 25_000_000
Image.MAX_IMAGE_PIXELS = MAX_IMAGE_PIXELS
def convert(data, fit="contain", profile="color", *, size=(1200, 1600)):
@@ -19,7 +20,7 @@ def convert(data, fit="contain", profile="color", *, size=(1200, 1600)):
with Image.open(BytesIO(data)) as source:
if source.format not in {"JPEG", "PNG", "WEBP"}:
raise ValueError()
if source.width * source.height > 25_000_000:
if source.width * source.height > MAX_IMAGE_PIXELS:
raise ValueError()
img = ImageOps.exif_transpose(source).convert("RGBA")
canvas = Image.new("RGBA", img.size, "white")