iT邦幫忙

第 12 屆 iT 邦幫忙鐵人賽

DAY 22
0
自我挑戰組

軟體開發隨筆雜記--試著解決問題系列 第 22

[Python]How to Extract Image Metadata in Python

顯示圖像內部資訊
https://www.thepythoncode.com/article/extracting-image-metadata-in-python
安裝環境

pip3 install Pillow

載入函式庫

from PIL import Image
from PIL.ExifTags import TAGS

這個功能只能作用於JPEG檔案
Now this will only work on JPEG image files, take any image you took and test it for this tutorial (if you want to test on my image, you'll find it in the tutorial's repository):

圖片路徑

imagename = "image.jpg"

用PIL讀取檔案

image = Image.open(imagename)

展開 EXIF data

exifdata = image.getexif()
for tag_id in exifdata:
    tag = TAGS.get(tag_id, tag_id)
    data = exifdata.get(tag_id)
    if isinstance(data, bytes):
        data = data.decode()
    print(f"{tag:25}: {data}")

上一篇
[Python]打包用pyinstaller和 virtualenv
下一篇
[Python][OpenCV]如何利用Tesserect OCR做辨識
系列文
軟體開發隨筆雜記--試著解決問題34

尚未有邦友留言

立即登入留言