core: simplify code
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
@ -7,22 +9,31 @@ from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from page import Page
|
||||
from album import Album
|
||||
|
||||
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 __init__(self, picture_path: Path, page = None, raw: Path|None = None, albums: list[Album] = [], is_repertoried: bool = True):
|
||||
self._large: Path = picture_path
|
||||
self._small: Path = Path(picture_path.get_absolute_path()[:-4] + "_small.jpg")
|
||||
self._export_file: Path = Path(picture_path.get_absolute_path() + ".out.pp3")
|
||||
self._raw: Path|None = raw
|
||||
self._page: Page = page
|
||||
self._albums: list[Album] = albums
|
||||
self._is_reperoried: bool = is_repertoried
|
||||
|
||||
def render(self) -> tuple[str, str, str]:
|
||||
if not self.small.exist():
|
||||
def get_small(self):
|
||||
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
|
||||
return self._small
|
||||
|
||||
def get_large(self):
|
||||
return self._large
|
||||
|
||||
def get_export_file(self):
|
||||
return self._export_file
|
||||
|
||||
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)
|
||||
im.save(self._small.get_absolute_path(), quality=95, optimize=True)
|
||||
|
||||
|
Reference in New Issue
Block a user