Bitcheck-image / app /utils /image_utils.py
JermaineAI's picture
feat: add upload and image utilities
0147634
raw
history blame contribute delete
751 Bytes
from __future__ import annotations
from pathlib import Path
from PIL import Image, ImageOps
def load_rgb_image(path: Path) -> Image.Image:
with Image.open(path) as img:
return ImageOps.exif_transpose(img).convert("RGB")
def image_properties(path: Path, original_filename: str, sha256: str) -> dict[str, object]:
with Image.open(path) as img:
width, height = img.size
return {
"filename": original_filename,
"sha256": sha256,
"width": width,
"height": height,
"format": img.format,
"color_mode": img.mode,
"aspect_ratio": round(width / height, 4) if height else None,
"file_size_bytes": path.stat().st_size,
}