feat: manage saved thumbnail plans and select plans for tasks
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user