本文整理汇总了Python中PIL.ExifTags.TAGS属性的典型用法代码示例。如果您正苦于以下问题:Python ExifTags.TAGS属性的具体用法?Python ExifTags.TAGS怎么用?Python ExifTags.TAGS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类PIL.ExifTags
的用法示例。
在下文中一共展示了ExifTags.TAGS属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: imreadRotate
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def imreadRotate(fn):
image=Image.open(fn)
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(image._getexif().items())
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)
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
print('dont rotate')
pass
return image
示例2: _get_image_original_date
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def _get_image_original_date(f_image):
img = Image.open(f_image)
exif_raw = img._getexif()
if exif_raw is None:
return None
exif = {}
for k, v in exif_raw.items():
if k in ExifTags.TAGS:
exif[ExifTags.TAGS[k]] = v
try:
return datetime.strptime(exif["DateTimeOriginal"], "%Y:%m:%d %H:%M:%S")
except:
return None
示例3: read_image
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def read_image(path):
image = Image.open(path)
for key in ExifTags.TAGS.keys():
if ExifTags.TAGS[key] == 'Orientation':
break
try:
exif = dict(image._getexif().items())
except AttributeError:
return image
if exif[key] == 3:
image = image.rotate(180, expand=True)
elif exif[key] == 6:
image = image.rotate(270, expand=True)
elif exif[key] == 8:
image = image.rotate(90, expand=True)
return image
示例4: exif
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def exif(filename):
image = Image.open(filename)
try:
exif = { TAGS[k]: v for k, v in image._getexif().items() if k in TAGS }
return exif
except AttributeError:
return {}
# }}}
# -- SAMPLE PAIR ATTACK --
# {{{ spa()
示例5: get_exif_data
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def get_exif_data(img_file):
"""Read EXIF data from the image.
img_file: Absolute path to the image file
Returns: A dictionary containing EXIF data of the file
Raises: NotAnImageFile if file is not an image
InvalidExifData if EXIF can't be processed
"""
try:
img = Image.open(img_file)
except (OSError, IOError):
raise NotAnImageFile
try:
# Use TAGS module to make EXIF data human readable
exif_data = {
TAGS[k]: v
for k, v in img._getexif().items()
if k in TAGS
}
except AttributeError:
raise InvalidExifData
# Add image format to EXIF
exif_data['format'] = img.format
return exif_data
示例6: generate_file_icon
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def generate_file_icon(file_path):
"""
Generates a small and a big thumbnail of an image
This will make it possible to preview the sent file
:param file_path: The path to the image
"""
im = Image.open(file_path)
# rotate according to EXIF tags
try:
exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS)
angles = {3: 180, 6: 270, 8: 90}
orientation = exif['Orientation']
if orientation in angles.keys():
im = im.rotate(angles[orientation], expand=True)
except AttributeError:
pass # no EXIF data available
# Big image
im.thumbnail((540, 540), Image.ANTIALIAS)
imgByteArr = io.BytesIO()
im.save(imgByteArr, format='JPEG2000')
file_icon = imgByteArr.getvalue()
# Small image
#im.thumbnail((64, 64), Image.ANTIALIAS)
#imgByteArr = io.BytesIO()
#im.save(imgByteArr, format='JPEG2000')
#small_file_icon = imgByteArr.getvalue()
return file_icon
示例7: initExif
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def initExif(self,image):
"""gets any Exif data from the photo"""
try:
self.exif_info={
ExifTags.TAGS[x]:y
for x,y in image._getexif().items()
if x in ExifTags.TAGS
}
self.exifvalid=True
except AttributeError:
print ("Image has no Exif Tags")
self.exifvalid=False
开发者ID:PacktPublishing,项目名称:Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition,代码行数:14,代码来源:photohandler.py
示例8: extract_exif
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def extract_exif(self, img):
if not hasattr(img, '_getexif'):
return
exif = img._getexif()
if exif is None:
return
make, model = '', ''
for num, value in exif.items():
try:
tag = ExifTags.TAGS[num]
except KeyError:
log.warning("Unknown EXIF code: %s", num)
continue
if tag == 'DateTimeOriginal':
self.update('created_at', self.parse_exif_date(value))
if tag == 'DateTime':
self.update('date', self.parse_exif_date(value))
if tag == 'Make':
make = value
if tag == 'Model':
model = value
generator = ' '.join((make, model))
self.update('generator', generator.strip())
示例9: generate_file_icon
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def generate_file_icon(file_path):
"""
Generates a small and a big thumbnail of an image
This will make it possible to preview the sent file
:param file_path: The path to the image
"""
im = Image.open(file_path)
# rotate according to EXIF tags
try:
exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS)
angles = {3: 180, 6: 270, 8: 90}
orientation = exif['Orientation']
if orientation in angles.keys():
im = im.rotate(angles[orientation], expand=True)
except (AttributeError, KeyError):
pass # no EXIF data available
# Big image
im.thumbnail((540, 540), Image.ANTIALIAS)
imgByteArr = io.BytesIO()
im.save(imgByteArr, format='JPEG2000')
file_icon = imgByteArr.getvalue()
# Small image
# im.thumbnail((64, 64), Image.ANTIALIAS)
# imgByteArr = io.BytesIO()
# im.save(imgByteArr, format='JPEG2000')
# small_file_icon = imgByteArr.getvalue()
return file_icon
示例10: process_exif_data
# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def process_exif_data(self):
"""Extract EXIF data from the image and add it to the model"""
# pylint: disable=protected-access
# Re-open the image
self.image.open()
image_file = StringIO(self.image.read())
image_file.seek(0)
# Open the image
original = PILImage.open(image_file)
# Find out if it is an image with EXIF data
if hasattr(original, '_getexif'):
exif = original._getexif()
if exif:
# Match the EXIF field codes to the tag name
self.exif = {
ExifTags.TAGS[code]: value
for (code, value) in original._getexif().items()
if code in ExifTags.TAGS
}
try:
# Save the image
self.save(process=False, update_fields=['exif'])
except UnicodeDecodeError:
# Oh well
pass
# Close out the file
image_file.close()