Update function rotate_by_exif.
This commit is contained in:
parent
fa619073f8
commit
568667f35c
1 changed files with 11 additions and 11 deletions
|
@ -12,10 +12,8 @@ from voussoirkit import pathclass
|
||||||
|
|
||||||
_exifread = exifread
|
_exifread = exifread
|
||||||
|
|
||||||
ORIENTATION_KEY = None
|
ORIENTATION_KEY = {val: key for (key, val) in PIL.ExifTags.TAGS.items()}.get('Orientation', None)
|
||||||
for (ORIENTATION_KEY, val) in PIL.ExifTags.TAGS.items():
|
GEOLOCATION_KEY = {ifd.name: ifd.value for ifd in PIL.ExifTags.IFD}.get('GPSInfo', None)
|
||||||
if val == 'Orientation':
|
|
||||||
break
|
|
||||||
|
|
||||||
def checkerboard_image(color_1, color_2, image_size, checker_size) -> PIL.Image:
|
def checkerboard_image(color_1, color_2, image_size, checker_size) -> PIL.Image:
|
||||||
'''
|
'''
|
||||||
|
@ -166,7 +164,7 @@ def replace_color(image, from_color, to_color):
|
||||||
pixels[x, y] = to_color
|
pixels[x, y] = to_color
|
||||||
return image
|
return image
|
||||||
|
|
||||||
def rotate_by_exif(image):
|
def rotate_by_exif(image, exif=None):
|
||||||
'''
|
'''
|
||||||
Rotate the image according to its exif data, so that it will display
|
Rotate the image according to its exif data, so that it will display
|
||||||
correctly even if saved without the exif.
|
correctly even if saved without the exif.
|
||||||
|
@ -176,12 +174,14 @@ def rotate_by_exif(image):
|
||||||
|
|
||||||
You should be able to call image.save('filename.jpg', exif=exif) with
|
You should be able to call image.save('filename.jpg', exif=exif) with
|
||||||
these returned values.
|
these returned values.
|
||||||
(To my knowledge, I can not put the exif back into the Image object itself.
|
|
||||||
There is getexif but no setexif or putexif, etc.)
|
To my knowledge, I can not put the exif back into the Image object itself.
|
||||||
|
There is getexif but no setexif or putexif, etc.
|
||||||
'''
|
'''
|
||||||
# Thank you Scabbiaza
|
# Thank you Scabbiaza
|
||||||
# https://stackoverflow.com/a/26928142
|
# https://stackoverflow.com/a/26928142
|
||||||
|
|
||||||
|
if exif is None:
|
||||||
try:
|
try:
|
||||||
exif = image.getexif()
|
exif = image.getexif()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
Loading…
Reference in a new issue