Make image crop target size configurable

This commit is contained in:
2026-01-25 16:54:01 +01:00
parent 56760e380d
commit 78f0f379fc
4 changed files with 45 additions and 7 deletions

View File

@@ -147,15 +147,22 @@ def _save_compressed_image(
img = img.convert("RGB")
# Optional crop
# NOTE: The front-end may already upload a cropped image (canvas export), but we still
# enforce aspect + maximum output size here for consistency.
target_w = int(current_app.config.get("IMAGE_CROP_TARGET_W", 1920) or 1920)
target_h = int(current_app.config.get("IMAGE_CROP_TARGET_H", 1080) or 1080)
target_w = max(1, target_w)
target_h = max(1, target_h)
if cm == "16:9":
img = _center_crop_to_aspect(img, 16, 9)
max_box = (1920, 1080)
max_box = (target_w, target_h)
elif cm == "9:16":
img = _center_crop_to_aspect(img, 9, 16)
max_box = (1080, 1920)
max_box = (target_h, target_w)
else:
# No crop: allow both portrait and landscape up to 1920px on the longest side.
max_box = (1920, 1920)
# No crop: allow both portrait and landscape up to target_w/target_h on the longest side.
max_box = (max(target_w, target_h),) * 2
# Resize down if very large (keeps aspect ratio)
img.thumbnail(max_box)