本文整理匯總了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()