Add exifread function.
This commit is contained in:
parent
3dd270bb4a
commit
abfaf27cee
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import copy
|
||||
import datetime
|
||||
import dateutil.parser
|
||||
import exifread
|
||||
import io
|
||||
import PIL.ExifTags
|
||||
import PIL.Image
|
||||
|
@ -82,12 +83,25 @@ def get_exif_datetime(image) -> datetime.datetime:
|
|||
if key in PIL.ExifTags.TAGS
|
||||
}
|
||||
exif_date = exif.get('DateTimeOriginal') or exif.get('DateTime') or exif.get('DateTimeDigitized')
|
||||
|
||||
if not exif_date:
|
||||
return
|
||||
return None
|
||||
|
||||
exif_date = re.sub(r'(\d\d\d\d):(\d\d):(\d\d)', r'\1-\2-\3', exif_date)
|
||||
return dateutil.parser.parse(exif_date)
|
||||
|
||||
def exifread(path) -> dict:
|
||||
if isinstance(path, PIL.Image.Image):
|
||||
handle = io.BytesIO()
|
||||
path.save(handle, format='JPEG', exif=path.getexif(), quality=10)
|
||||
handle.seek(0)
|
||||
elif isinstance(path, pathclass.Path):
|
||||
handle = path.open('rb')
|
||||
elif isinstance(path, str):
|
||||
handle = open(path, 'rb')
|
||||
|
||||
return exifread.process_file(handle)
|
||||
|
||||
def pad_to_square(image, background_color=None) -> PIL.Image:
|
||||
'''
|
||||
If the given image is not already square, return a new, square image with
|
||||
|
|
Loading…
Reference in a new issue