我正在使用PIL。如何將EXIF數據轉換爲字典?在Python中,如何讀取圖像的exif數據?
68
A
回答
108
試試這個:
import PIL.Image
img = PIL.Image.open('img.jpg')
exif_data = img._getexif()
這應該給你通過EXIF數字標籤索引的字典。如果您想通過實際的EXIF標籤名稱字符串索引的字典中,你可以試試:
import PIL.ExifTags
exif = {
PIL.ExifTags.TAGS[k]: v
for k, v in img._getexif().items()
if k in PIL.ExifTags.TAGS
}
+5
任何Python 3的替代? – 2013-08-30 04:57:31
20
您也可以使用ExifRead模塊:
import exifread
# Open image file for reading (binary mode)
f = open(path_name, 'rb')
# Return Exif tags
tags = exifread.process_file(f)
11
我用這個:
import os,sys
from PIL import Image
from PIL.ExifTags import TAGS
for (k,v) in Image.open(sys.argv[1])._getexif().iteritems():
print '%s = %s' % (TAGS.get(k), v)
或獲取特定字段:
def get_field (exif,field) :
for (k,v) in exif.iteritems():
if TAGS.get(k) == field:
return v
exif = image._getexif()
print get_field(exif,'ExposureTime')
相關問題
- 1. 閱讀黑莓圖像的EXIF數據
- 2. 讀取的Exif數據8.1
- 3. 從python的在線圖像獲取exif數據
- 4. 如何從回形針附加的圖像中讀取exif數據?
- 5. 閱讀在Qt中圖像的exif元數據
- 6. 如何在使用DKImagePickerController時使用exif數據獲取圖像?
- 7. 使用Ruby從遠程圖像高效讀取EXIF元數據
- 8. 如何修改python中的EXIF數據
- 9. 如何從Python中的URL讀取圖像數據?
- 10. Codeigniter strip圖像EXIF數據
- 11. 從JPG中讀取EXIF數據
- 12. Exif數據讀寫
- 13. 如何使用OpenCV獲取圖像Exif數據?
- 14. 從圖像中剝離EXIF數據
- 15. 在不下載整個圖像的情況下獲取EXIF數據 - Python
- 16. EXIF數據讀取和寫入
- 17. 從一個字節讀取EXIF數據[]
- 18. 圖像的exif數據代碼
- 19. 圖片exif /元數據閱讀/寫作?
- 20. 如何讀取Python中的cx_Oracle.LOB數據?
- 21. 從Cocoa的圖像中讀取EXIF/IPTC信息
- 22. 如何讀取圖像中的數字?
- 23. 如何從CarrierWave圖像中刪除EXIF(相機)數據?
- 24. 如何從安卓相機圖像中刪除EXIF數據
- 25. 在新Activity中將EXIF數據讀取到textView中
- 26. nodejs讀取圖像數據
- 27. 從PDF中的圖像讀取數據
- 28. 在Python中刪除EXIF數據?
- 29. Python - 如何從URL讀取圖像?
- 30. 如何用C++或python從圖像中讀取圖像描述?
更近期的問題在這裏:http://stackoverflow.com/questions/14009148/exif-reading-library – 2013-04-24 12:58:59
請參閱這裏的答案:http://stackoverflow.com/questions/765396/exif-manipulation-library-for-python – 2011-01-22 00:05:19
http://tilloy.net/dev/pyexiv2/tutorial.html這是最簡單和最全面的。 – 2012-11-17 19:10:49