core: use class based code

This commit is contained in:
2025-04-14 19:29:54 +02:00
parent c68f393703
commit 8a123180c5
5 changed files with 163 additions and 87 deletions

28
src/picture.py Normal file
View File

@ -0,0 +1,28 @@
from PIL import Image
import os
from path import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from page import Page
class Picture():
def __init__(self, picture_path: Path, page = None, raw: Path|None = None):
self.large: Path = picture_path
self.small: Path = Path(picture_path.get_dirpath(), picture_path.get_name()[:-4] + "_small.jpg")
self.export_file: Path = Path(picture_path, ".out.pp3")
self.raw: Path|None = raw
self.page: Page = page
def render(self) -> tuple[str, str, str]:
if not self.small.exist():
self.gen_small()
return self.large.get_name(), self.small.get_name(), self.export_file.get_name() if self.export_file.exist() else None
def gen_small(self):
im = Image.open(self.large.get_absolute_path()).convert("RGB")
im.save(self.small.get_absolute_path(), quality=95, optimize=True)