Skip to content

Commit

Permalink
✨ Implemented image util function for rotating based on meta-data
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertSuarez committed Apr 9, 2021
1 parent 2e9102e commit c366636
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion multiplexer/src/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import requests

from PIL import Image, ImageFile
from PIL import Image, ImageFile, ImageOps
from src import TMP_FOLDER
from src.utils import log, storage

Expand Down Expand Up @@ -106,6 +106,20 @@ def get_dimensions(image_path):
return img.size


def rotate(image_path):
"""
Rotate an image based on meta-data from its path.
:param image_path: Image path to retrieve dimensions.
:return: Image rotated.
"""
try:
with Image.open(image_path) as img:
img = ImageOps.exif_transpose(img)
img.save(image_path, format=img.format, quality=95)
except Exception as e:
log.warn(f'Cannot rotate input image: [{e}]')


def resize(image_path, target_dimensions, image_format):
"""
Resize image given the target dimensions, saving it in the same file.
Expand Down

0 comments on commit c366636

Please sign in to comment.