File size: 751 Bytes
0147634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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,
        }