本文整理匯總了Python中exifread.process_file方法的典型用法代碼示例。如果您正苦於以下問題:Python exifread.process_file方法的具體用法?Python exifread.process_file怎麽用?Python exifread.process_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exifread
的用法示例。
在下文中一共展示了exifread.process_file方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: JPEGMeta
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def JPEGMeta(image):
"""Deprecated -- This is effectively being replaced by the MultiHandler.Exif."""
meta = ""
# Open up the file for reading
with open(image.veritas.file_name,"rb") as jpegFile:
tags = exifread.process_file(jpegFile)
for tag in tags:
meta += "{0}:\t{1}\n".format(tag,tags[tag])
# Show it to the user
print("Exif Data\n=========\n{0}\n".format(meta))
# Save it off
with open(os.path.join(image.veritas.results_directory,"metadata"),"w") as out:
out.write(meta)
示例2: process_image
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def process_image(byte64_jpeg, filename):
attch_data = str(base64.b64decode(byte64_jpeg))
buf = cStringIO.StringIO(attch_data)
gps = {}
try:
tags = exifread.process_file(buf)
except:
# TODO this may die because of the UNICODE set being unprintable in the console
# print u"failed to process tags for filename {}. Exception: {}".format(filename, sys.exc_info()[0])
print u"failed to process tags for. Exception: {}".format(sys.exc_info()[0])
return gps
if tags and len(tags) > 0:
if "GPS GPSLatitudeRef" in tags:
gps["latref"] = tags["GPS GPSLatitudeRef"].printable
if "GPS GPSLongitudeRef" in tags:
gps["lonref"] = tags["GPS GPSLongitudeRef"].printable
if "GPS GPSAltitudeRef" in tags:
gps["altref"] = tags["GPS GPSAltitudeRef"].printable
if "GPS GPSLatitude" in tags:
gps["lat"] = (1 if "latref" in gps and gps["latref"] == "N" else -1 ) * ratio_to_dms(tags["GPS GPSLatitude"].values)
if "GPS GPSLongitude" in tags:
gps["lon"] = (1 if "lonref" in gps and gps["lonref"] == "E" else -1 ) * ratio_to_dms(tags["GPS GPSLongitude"].values)
if "GPS GPSAltitude" in tags:
gps["alt"] = tags["GPS GPSAltitude"].printable
# TODO this may die because of the UNICODE set being unprintable in the console
# else:
# print u"No exif gps tags for: {} ".format(filename)
return gps
# Validate lat lon
示例3: all_tags
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def all_tags(path) -> {str: str}:
"""Method to return Exif tags"""
file = open(path, "rb")
tags = exifread.process_file(file, details=False)
return tags
示例4: gps_filename_dict
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def gps_filename_dict(images_list):
"""Returns the filename of the image and its GPS Coordinates
as dictionary data structure."""
# List which will hold the coordinate pairs and pixel values
coordinates_dict = OrderedDict()
# Produce the text for each image in the stack
for file_name in images_list:
# Open image file for reading (binary mode) and processing with PIL
f = open(file_name, 'rb')
# Return Exif tags
tags = exifread.process_file(f)
# Initializing some variables
GPS_Longitude = 0
GPS_Latitude = 0
# Returns all the GPS Related Metadata
for tag in tags.keys():
if tag == 'GPS GPSLongitude':
GPS_Longitude = parse_GPS_Lat_Lon(tags[tag])
#Change from sexagesimal to decimal/degree notation
GPS_Longitude = sexag_to_dec(GPS_Longitude)
elif tag == 'GPS GPSLatitude':
GPS_Latitude = parse_GPS_Lat_Lon(tags[tag])
# Change from sexagesimal to decimal/degree notation
GPS_Latitude = sexag_to_dec(GPS_Latitude)
if GPS_Latitude and GPS_Longitude:
coordinates_dict[file_name] = (GPS_Latitude, GPS_Longitude)
return coordinates_dict
# Returns a dict of utm coord {filename: utm}
示例5: exif_info
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def exif_info(filename):
print ("Extraction of EXIF data from: %s" % (filename,))
f = open(filename,'rb')
tags = exifread.process_file(f)
for tag in tags.keys():
if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
type_tag = tag.split(" ", 1)[0]
tag_key = tag.split(" ", 1)[1]
helper.sqlite_insert(tag_key,tags[tag],os.path.basename(filename))
return filename
示例6: exif_creation_timestamp
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def exif_creation_timestamp(path: str) -> str:
with open(path, 'rb') as f:
tags = exifread.process_file(f, details=False)
if 'EXIF DateTimeOriginal' in tags:
return str(tags['EXIF DateTimeOriginal'])
elif 'EXIF DateTimeDigitized' in tags:
return str(tags['EXIF DateTimeDigitized'])
raise MissingExifTimestampError()
示例7: __init__
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def __init__(self, filename, details=False):
'''
Initialize EXIF object with FILE as filename or fileobj
'''
self.filename = filename
if type(filename) == str:
with open(filename, 'rb') as fileobj:
self.tags = exifread.process_file(fileobj, details=details)
else:
self.tags = exifread.process_file(filename, details=details)
示例8: opExif
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def opExif(file_path, file_name):
# 拚接出原文件路徑
old_full_name = os.path.join(file_path, file_name)
# 拿到原文件後綴
file_suffix = os.path.splitext(file_name)[1]
# 打開並讀取文件頭部的EXIF信息
with open(old_full_name, "rb") as f:
tags = exifread.process_file(f)
# EXIF信息中拍攝時間的標簽
Tag = "EXIF DateTimeOriginal"
if Tag in tags:
# 調整原始的時間格式為"年月日_時分秒"
file_stem = str(tags[Tag]).replace(':', '').replace(' ', '_')
# 新文件名:年月日_時分秒.原後綴名
new_name = file_stem + file_suffix
num = 1
# 遇到拍攝時間相同則添加序號做以區分
while os.path.exists(new_name):
# 新文件名:年月日_時分秒_序號.原後綴名
new_name = file_stem + '_' + str(num) + file_suffix
num += 1
# 拚接出新文件路徑
new_full_name = os.path.join(file_path, new_name)
print(f"{old_full_name} >>> {new_full_name}")
# 執行重命名操作
os.rename(old_full_name, new_full_name)
else:
print(f"No {Tag} found in: {old_full_name}")
# 修改要處理的目錄
示例9: reorient_image
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def reorient_image(cls, img):
"""re-orients rotated images by looking at EXIF data
"""
# get the image rotation from EXIF information
import exifread
file_full_path = img.filename
with open(file_full_path) as f:
tags = exifread.process_file(f)
orientation_string = tags.get('Image Orientation')
from PIL import Image
if orientation_string:
orientation = orientation_string.values[0]
if orientation == 1:
# do nothing
pass
elif orientation == 2: # flipped in X
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3: # rotated 180 degree
img = img.transpose(Image.ROTATE_180)
elif orientation == 4: # flipped in Y
img = img.transpose(Image.FLIP_TOP_BOTTOM)
elif orientation == 5: #
img = img.transpose(Image.ROTATE_270)
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 6:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 7:
img = img.transpose(Image.ROTATE_90)
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 8:
img = img.transpose(Image.ROTATE_90)
return img
示例10: get_image_tags
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def get_image_tags(image_path):
f = open(image_path, 'rb')
tags = exifread.process_file(f)
return tags
示例11: __get_image_ability
# 需要導入模塊: import exifread [as 別名]
# 或者: from exifread import process_file [as 別名]
def __get_image_ability(self):
"""
獲取圖片的屬性值,包含:經緯度、拍攝時間等
:param picture_name:
:return:
"""
# 利用exifread庫,讀取圖片的屬性
img_exif = exifread.process_file(open(self.img_path, 'rb'))
# 能夠讀取到屬性
if img_exif:
# 緯度數
latitude_gps = img_exif['GPS GPSLatitude']
# N,S 南北緯方向
latitude_direction = img_exif['GPS GPSLatitudeRef']
# 經度數
longitude_gps = img_exif['GPS GPSLongitude']
# E,W 東西經方向
longitude_direction = img_exif['GPS GPSLongitudeRef']
# 拍攝時間
take_time = img_exif['EXIF DateTimeOriginal']
is_lie = self.judge_time_met(take_time)
if is_lie:
print('很遺憾的通知你,你的女朋友在撒謊!!!')
return
# 緯度、經度、拍攝時間
if latitude_gps and longitude_gps and take_time:
# 對緯度、經度值原始值作進一步的處理
latitude = self.__format_lati_long_data(latitude_gps)
longitude = self.__format_lati_long_data(longitude_gps)
# print(f'{longitude},{latitude}')
# 注意:由於gps獲取的坐標在國內高德等主流地圖上逆編碼不夠精確,這裏需要轉換為火星坐標係
location = wgs84togcj02(longitude, latitude)
return f'{location[0]},{location[1]}'
else:
print(f'獲取的圖片數據屬性不完整')
return ''
else:
print('抱歉,圖片不是原圖,沒法獲取到圖片屬性。')
return ''