ImageTool.py 745 B

123456789101112131415161718192021222324
  1. from PIL import Image, UnidentifiedImageError
  2. import os
  3. from logger import logger
  4. def rotate_image(path_file: str, gradus: int = -90) -> str:
  5. try:
  6. image = Image.open(path_file, 'r')
  7. rotate_path_image = os.path.join(
  8. os.path.dirname(image.filename),
  9. F"rotate_{os.path.split(image.filename)[1]}"
  10. )
  11. rotate_img = image.rotate(gradus, expand=True)
  12. rotate_img.save(rotate_path_image)
  13. return rotate_path_image
  14. except FileNotFoundError:
  15. logger.error(F"Файл не найден: {path_file=}")
  16. return None
  17. except UnidentifiedImageError:
  18. logger.error(F"Не правильный формат: {path_file=}")
  19. return None