Guide to Extract Image Metadata in Python

pip install Pillow
pip install prettytable
#load modules
from PIL import Image
from PIL.ExifTags import TAGS
from prettytable import PrettyTable
image_filename = "image.jpg"

#initialiting prettytable object
table = PrettyTable()

#setting table feilds name
table.field_names = ["MetaTags", "Values"]
#load image
my_image = Image.open(image_filename)
for id  in img_exif_data:
tag_name = TAGS.get(id, id)
data = img_exif_data.get(id)

#if data in bytes
if isinstance(data, bytes):
data = data.decode()
#add tag name and data into table
table.add_row([tag_name, data])

#display data
print(table)
#load modules
from PIL import Image
from PIL.ExifTags import TAGS
from prettytable import PrettyTable

image_filename = "image.jpg"

#initialiting prettytable object
table = PrettyTable()

#setting table feilds name
table.field_names = ["MetaTags", "Values"]

#load image
my_image = Image.open(image_filename)

#get EXIF standared Data of the image
img_exif_data = my_image.getexif()

for id in img_exif_data:
tag_name = TAGS.get(id, id)
data = img_exif_data.get(id)

#if data in bytes
if isinstance(data, bytes):
data = data.decode()

table.add_row([tag_name, data])

print(table)
+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| MetaTags | Values |
+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ExifVersion | 0220 |
| ComponentsConfiguration | |
| ShutterSpeedValue | 9.965 |
| DateTimeOriginal | 2020:08:19 10:49:13 |
| DateTimeDigitized | 2020:08:19 10:49:13 |
| ApertureValue | 1.44 |
| BrightnessValue | 5.5 |
| ExposureBiasValue | nan |
| MaxApertureValue | 1.44 |
| MeteringMode | 2 |
| LightSource | 21 |
| Flash | 16 |
| FocalLength | 4.755 |
| ColorSpace | 1 |
| ExifImageWidth | 8000 |
| SceneCaptureType | 0 |
| SubsecTime | 750682 |
| SubsecTimeOriginal | 750682 |
| SubsecTimeDigitized | 750682 |
| ExifImageHeight | 6000 |
| ImageLength | 6000 |
| Make | OnePlus |
| Model | HD1901 |
| SensingMethod | 1 |
| Orientation | 1 |
| YCbCrPositioning | 1 |
| ExposureTime | 0.001 |
| ExifInteroperabilityOffset | 791 |
| XResolution | 72.0 |
| FNumber | 1.65 |
| SceneType | |
| YResolution | 72.0 |
| ExposureProgram | 1 |
| GPSInfo | {1: 'N', 2: (29.0, 52.0, 46.6535), 3: 'E', 4: (79.0, 20.0, 54.5711), 5: b'\x00', 6: 0.0, 7: (5.0, 19.0, 13.0), 27: b'ASCII\x00\x00\x00CELLID\x00', 29: '2020:08:19'} |
| ISOSpeedRatings | 200 |
| ResolutionUnit | 2 |
| ExposureMode | 1 |
| FlashPixVersion | 0100 |
| ImageWidth | 8000 |
| WhiteBalance | 0 |
| DateTime | 2020:08:19 10:49:13 |
| FocalLengthIn35mmFilm | 27 |
| ExifOffset | 210 |
| MakerNote | MM * |
+----------------------------+------------------------------------------------------------------------------------------------------------------------------------------

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store