| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import pathlib
- from .image import image
- from .exception import directory_image_exception
- class directory_image:
- def __init__(self, target: pathlib.Path, thumbnail: int = 400) -> None:
- self.__target = target
- self.__thumbnail_size = thumbnail
- if not self.__target.is_dir():
- content = "Directory for image hosting: \""
- content = content + str(target) + "\"."
- raise directory_image_exception(content)
-
- @property
- def thumbnail_size(self) -> int:
- return self.__thumbnail_size
- @property
- def target(self) -> pathlib.Path:
- return self.__target
- def __name_full(self, image_id: int) -> str:
- return "full_" + str(image_id) + "_.png"
- def __name_thumbnail(self, image_id: int) -> str:
- return "thumbnail_" + str(image_id) + "_.webp"
- def __full_path(self, image_id: int) -> pathlib.Path:
- return self.target / pathlib.Path(self.__full_name(image_id))
- def __thumbnail_path(self, image_id: int) -> pathlib.Path:
- return self.target / pathlib.Path(self.__thumbnail_name(image_id))
- def store(self, coded: str, image_id: int) -> None:
- full = self.__full_path(image_id)
- thumbnail = self.__full_path(image_id)
-
- image(coded, self.thumbnail_size) \
- .save_full(full) \
- .save_thumbnail(thumbnail)
|