Photo basics (#10)
Tests / test_and_lint (push) Successful in 10s

Reviewed-on: #10
Co-authored-by: Mathias Scheider <mathias2784@web.de>
This commit was merged in pull request #10.
This commit is contained in:
2026-09-30 21:01:20 +00:00
committed by mathias2784
parent d9758c598d
commit 0c33153c98
11 changed files with 390 additions and 9 deletions
+21 -8
View File
@@ -1,15 +1,28 @@
import base64
from io import BytesIO
from pathlib import Path
from PIL import Image
class Photo:
def __init__(self): ...
def __init__(self, path: Path):
self.path = path
self.image = Image.open(path)
@classmethod
def from_file(cls, path: Path) -> Photo:
# TODO
return cls()
def resize(self) -> Photo:
# TODO
def resize(self, image_max_size=1024) -> Photo:
"""Limiting max dimensions while maintaining aspect ratio"""
self.image.thumbnail((image_max_size, image_max_size), Image.Resampling.LANCZOS)
return self
def to_rgb(self):
if self.image.mode != "RGB":
self.image = self.image.convert("RGB")
return self
def get_encoded(self):
buffer = BytesIO()
self.image.save(buffer, format="JPEG", quality=85)
image_data = base64.b64encode(buffer.getvalue()).decode("utf-8")
return image_data
+8
View File
@@ -1,6 +1,14 @@
from pathlib import Path
from pydantic_core import Url
from pydantic_settings import BaseSettings, SettingsConfigDict
PHOTOOLS3_DIR = Path(__file__).parent.resolve()
SRC_DIR = PHOTOOLS3_DIR.parent
ROOT_DIR = SRC_DIR.parent
EXAMPLES_DIR = ROOT_DIR / "examples"
DNG_EXAMPLES_DIR = EXAMPLES_DIR / "dng"
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env")