diff --git a/mockup_package/mockup/image_generator.py b/mockup_package/mockup/image_generator.py index d293e26..1f3c287 100755 --- a/mockup_package/mockup/image_generator.py +++ b/mockup_package/mockup/image_generator.py @@ -1,6 +1,6 @@ import os import mockup.helpers as h -from PIL import Image +from PIL import Image, ExifTags import cv2 import numpy as np @@ -38,6 +38,23 @@ def __init__(self, original_img_path, phone_slug, device_info): def create_fit_resolution_image(self): device_ratio = self.d_size[0] / self.d_size[1] image = Image.open(self.original_img_path).convert("RGBA") + + # Solve image orientation issue: + # some picture has orientation property, which the browser knows and can automatically rotate the image # noqa: E501 + # but the property is lost when we mockup the image, so need to fix it manually. # noqa: E501 + # ref: https://stackoverflow.com/questions/13872331/rotating-an-image-with-orientation-specified-in-exif-using-python-without-pil-in # noqa: E501 + for orientation in ExifTags.TAGS.keys(): + if ExifTags.TAGS[orientation] == "Orientation": + break + + exif = image.getexif() + if exif[orientation] == 3: + image = image.rotate(180, expand=True) + elif exif[orientation] == 6: + image = image.rotate(270, expand=True) + elif exif[orientation] == 8: + image = image.rotate(90, expand=True) + find_original_image_dim_process = str(image.size[0]) + "x" + str(image.size[1]) original_image_dim = tuple( map( diff --git a/public/mockup.zip b/public/mockup.zip index b7ef8e2..0124c4b 100644 Binary files a/public/mockup.zip and b/public/mockup.zip differ