first commit

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kunkunxiaomaoandClaude committed 2026-11-16 20:45:22 +08:00
commit 9c5fef1a4d
412 files changed
+94582

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
from __future__ import annotations
from pathlib import Path
from PIL import Image, ImageOps
from sakura_cloud.core.config import settings
def thumbnail_path_for(storage_path: str | Path) -> Path:
source = Path(storage_path)
return source.with_name(f"{source.stem}.thumb.webp")
def generate_webp_thumbnail(storage_path: str | Path) -> str | None:
source = Path(storage_path)
if not source.is_file():
return None
target = thumbnail_path_for(source)
try:
with Image.open(source) as image:
image = ImageOps.exif_transpose(image)
image.thumbnail((settings.thumbnail_max_size, settings.thumbnail_max_size))
if image.mode not in {"RGB", "RGBA"}:
image = image.convert("RGB")
target.parent.mkdir(parents=True, exist_ok=True)
image.save(target, "WEBP", quality=settings.thumbnail_quality, method=6)
return str(target)
except Exception:
return None