Python 3:处理文件和数字资产/图像/EXIF 数据
外观
%pip install pillow
pip install pillow
代码片段[1]
from PIL import Image
from PIL.ExifTags import TAGS as exif_tags
# location of the image you want to extract the exif information from
location_of_file: str = ''
def retrievement_of_exif_table(
exif_information
) -> dict:
exif_table: dict = {}
for key, value in exif_information.items():
exif_label = exif_tags.get(key)
if not(
exif_label is None
):
exif_table[exif_label] = value
return exif_table
exif_table = {}
with Image.open(location_of_file) as image:
exif_table = retrievement_of_exif_table(
image.getexif()
)
代码片段[1]
from PIL.ExifTags import GPS, GPSTAGS
# .....
def convert_gps_information(
information
) -> dict:
gps_information: dict = {}
for key in information.keys():
gps_label = GPSTAGS.get(key)
gps_information[gps_label] = information[key]
return gps_information
def retrievement_of_exif_table(
exif_information
) -> dict:
# .....
for key, value in exif_information.items():
exif_label = exif_tags.get(key)
if exif_label == 'GPSInfo':
value = convert_gps_information(
exif_information.get_ifd(
key
)
)
# .....
- ↑ a b "image exif information tutorial.ipynb". Gist. Retrieved 2023-07-12.