feat: manage saved thumbnail plans and select plans for tasks
Community checks / verify (push) Skipped
Verify Frame Flow / verify (push) Failing after 5m58s

This commit is contained in:
渡口浪人
2026-10-23 14:47:27 +08:00
parent d94031eb50
commit 7178235022
17 changed files with 1736 additions and 37 deletions
+11 -3
View File
@@ -17,7 +17,15 @@ MAX_IMAGE_PIXELS = 25_000_000
Image.MAX_IMAGE_PIXELS = MAX_IMAGE_PIXELS
def convert(data, fit="contain", profile="color", *, size=(1200, 1600)):
def convert(
data,
fit="contain",
profile="color",
*,
size=(1200, 1600),
centering=(0.5, 0.5),
quality=93,
):
try:
with Image.open(BytesIO(data)) as source:
if source.format not in {"JPEG", "PNG", "WEBP"}:
@@ -33,7 +41,7 @@ def convert(data, fit="contain", profile="color", *, size=(1200, 1600)):
img, size, method=Image.Resampling.LANCZOS, color="white"
)
else:
center = (0.5, 0.5)
center = centering
if fit == "smart":
# Lightweight edge saliency: slide an aspect-correct window
# over a thumbnail; retain the region with most detail.
@@ -65,7 +73,7 @@ def convert(data, fit="contain", profile="color", *, size=(1200, 1600)):
if profile == "grayscale":
result = ImageOps.grayscale(result).convert("RGB")
out = BytesIO()
result.save(out, "JPEG", quality=93, optimize=True)
result.save(out, "JPEG", quality=quality, optimize=True)
return out.getvalue()
except (OSError, ValueError, Image.DecompressionBombError):
raise FlowError(E.INVALID_REQUEST, "Unsupported or invalid image") from None