Skip to content

Commit a062570

Browse files
Merge pull request #225 from HaripriyaB/image_metadata
Extract metadata of a given Image
2 parents 898628f + 750b7a3 commit a062570

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Extract Image Metadata
2+
The aim of the program is to generate the metatdata of an image given as input. Metadata is "data that provides information about other data". In other words, it is "data about data".
3+
4+
## Libraries Used:
5+
* Python [Pillow](https://pypi.org/project/Pillow/) - Python Imaging Library
6+
7+
## Prerequisites:
8+
Install Pillow using the following command(pip/pip3):
9+
10+
`>> pip3 install Pillow`
11+
12+
## Usage:
13+
14+
Sample images given along with the source code
15+
16+
```
17+
Enter path to the image file: $(imagename)
18+
19+
<If there exists Metadata of the input image, then it goes below>
20+
21+
Sample:
22+
23+
ExifVersion : 0220
24+
ComponentsConfiguration :
25+
ShutterSpeedValue : 5.643
26+
DateTimeOriginal : 2020:08:13 14:04:39
27+
DateTimeDigitized : 2020:08:13 14:04:39
28+
ApertureValue : 1.69
29+
BrightnessValue : 0.55
30+
ExposureBiasValue : 0.0
31+
MaxApertureValue : 1.69
32+
MeteringMode : 2
33+
Flash : 0
34+
FocalLength : 5.23
35+
ColorSpace : 1
36+
ExifImageWidth : 2888
37+
FocalLengthIn35mmFilm : 24
38+
SceneCaptureType : 0
39+
ExifImageHeight : 1984
40+
Model : SM-A715F
41+
Orientation : 1
42+
Make : samsung
43+
SensingMethod : 1
44+
XResolution : 72.0
45+
YResolution : 72.0
46+
ExposureProgram : 2
47+
GPSInfo : {29: '2020:08:13', 5: b'\x00', 6: 0.0}
48+
ISOSpeedRatings : 250
49+
ResolutionUnit : 2
50+
ExposureMode : 0
51+
FlashPixVersion : 0100
52+
WhiteBalance : 0
53+
Software : A715FXXU2ATG1
54+
DateTime : 2020:08:13 14:05:15
55+
ExifOffset : 202
56+
SubsecTime : 701285
57+
SubsecTimeOriginal : 701285
58+
SubsecTimeDigitized : 701285
59+
ExposureTime : 0.02
60+
FNumber : 1.8
61+
62+
<If no metadata available, then it shows>
63+
64+
No Metadata available for this image!
65+
66+
```
67+
68+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from PIL import Image
2+
from PIL.ExifTags import TAGS
3+
4+
# path to the image or video
5+
imagename = input("Enter path to the image file: ")
6+
7+
# read the image data using PIL
8+
try:
9+
image = Image.open(imagename)
10+
except:
11+
print("Image not readable!")
12+
exit()
13+
14+
# extract EXIF data
15+
exifdata = image.getexif()
16+
17+
# If no metadata is available for the image
18+
if len(exifdata) == 0:
19+
print("No Metadata available for this image!")
20+
21+
# iterating over all EXIF data fields
22+
for tag_id in exifdata:
23+
# get the tag name, instead of human unreadable tag id
24+
tag = TAGS.get(tag_id, tag_id)
25+
data = exifdata.get(tag_id)
26+
# decode bytes
27+
if isinstance(data, bytes):
28+
data = data.decode()
29+
print(f"{tag:25}: {data}")
9.18 KB
Loading
3.8 MB
Loading

0 commit comments

Comments
 (0)