polish nouri 0.6.0 startup and desktop header

This commit is contained in:
2026-04-12 17:50:17 +02:00
parent 555fddab80
commit a26d519cf2
4 changed files with 23 additions and 6 deletions
+13 -1
View File
@@ -4,10 +4,18 @@ import os
import uuid
from pathlib import Path
from PIL import Image, ImageOps, UnidentifiedImageError
from werkzeug.datastructures import FileStorage
from werkzeug.utils import secure_filename
try:
from PIL import Image, ImageOps, UnidentifiedImageError
PILLOW_AVAILABLE = True
except ImportError: # pragma: no cover - local fallback when Pillow is unavailable
Image = None
ImageOps = None
UnidentifiedImageError = OSError
PILLOW_AVAILABLE = False
ALLOWED_IMAGE_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "webp"}
IMAGE_VARIANTS = {
@@ -54,6 +62,8 @@ def remove_photo_assets(upload_folder: str | Path, filename: str | None) -> None
def _open_image(upload: FileStorage) -> Image.Image:
if not PILLOW_AVAILABLE or Image is None or ImageOps is None:
raise OSError("Pillow ist nicht verfügbar.")
upload.stream.seek(0)
image = Image.open(upload.stream)
image.load()
@@ -61,6 +71,8 @@ def _open_image(upload: FileStorage) -> Image.Image:
def _prepare_image(image: Image.Image) -> Image.Image:
if not PILLOW_AVAILABLE:
return image
if image.mode not in {"RGB", "RGBA"}:
image = image.convert("RGBA" if "A" in image.getbands() else "RGB")
return image