Skip to content

Commit 650f4f4

Browse files
committed
added image metadata extractor tutorial
1 parent 706c46c commit 650f4f4

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
2424
- [How to Build a XSS Vulnerability Scanner in Python](https://www.thepythoncode.com/article/make-a-xss-vulnerability-scanner-in-python). ([code](ethical-hacking/xss-vulnerability-scanner))
2525
- [How to Use Hash Algorithms in Python using hashlib](https://www.thepythoncode.com/article/hashing-functions-in-python-using-hashlib). ([code](ethical-hacking/hashing-functions/))
2626
- [How to Brute Force FTP Servers in Python](https://www.thepythoncode.com/article/brute-force-attack-ftp-servers-using-ftplib-in-python). ([code](ethical-hacking/ftp-cracker))
27+
- [How to Extract Image Metadata in Python](https://www.thepythoncode.com/article/extracting-image-metadata-in-python). ([code](ethical-hacking/image-metadata-extractor))
2728

2829
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
2930
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)

Diff for: ethical-hacking/image-metadata-extractor/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [How to Extract Image Metadata in Python](https://www.thepythoncode.com/article/extracting-image-metadata-in-python)
2+
To run this:
3+
- `pip3 install -r requirements.txt`
4+
- Extract metadata of the image `image.jpg`:
5+
```
6+
python image_metadata_extractor.py image.jpg
7+
```

Diff for: ethical-hacking/image-metadata-extractor/image.jpg

3.8 MB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from PIL import Image
2+
from PIL.ExifTags import TAGS
3+
import sys
4+
5+
# path to the image or video
6+
imagename = sys.argv[1]
7+
8+
# read the image data using PIL
9+
image = Image.open(imagename)
10+
11+
# extract EXIF data
12+
exifdata = image.getexif()
13+
14+
# iterating over all EXIF data fields
15+
for tag_id in exifdata:
16+
# get the tag name, instead of human unreadable tag id
17+
tag = TAGS.get(tag_id, tag_id)
18+
data = exifdata.get(tag_id)
19+
# decode bytes
20+
if isinstance(data, bytes):
21+
data = data.decode()
22+
print(f"{tag:25}: {data}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pillow

0 commit comments

Comments
 (0)