123456789101112131415161718192021222324 |
- from PIL import Image, UnidentifiedImageError
- import os
- from logger import logger
- def rotate_image(path_file: str, gradus: int = -90) -> str:
- try:
- image = Image.open(path_file, 'r')
- rotate_path_image = os.path.join(
- os.path.dirname(image.filename),
- F"rotate_{os.path.split(image.filename)[1]}"
- )
-
- rotate_img = image.rotate(gradus, expand=True)
- rotate_img.save(rotate_path_image)
-
- return rotate_path_image
-
- except FileNotFoundError:
- logger.error(F"Файл не найден: {path_file=}")
- return None
- except UnidentifiedImageError:
- logger.error(F"Не правильный формат: {path_file=}")
- return None
|