Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 49577ca

Browse files
Get Image Metadata Added
1 parent e1fc461 commit 49577ca

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

‎Get Image Metadata/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Get Image Metadata
2+
The python script gets all the metadata from the image
3+
4+
What the program does?
5+
- Takes image file(s) as input at the same time
6+
- Gets all the metadata from the image
7+
8+
### Requirements
9+
>Python3.6+
10+
>
11+
> pip install -r requirements.txt
12+
13+
14+
### Usage
15+
```
16+
img_meta.py [-h] -f FILES [FILES ...]
17+
18+
EXTRACT METADATA IN IMAGES
19+
20+
optional arguments:
21+
-h, --help show this help message and exit
22+
-f FILES [FILES ...] Image File(s)
23+
```
24+
25+
### Contribution
26+
Any kind of contributions are welcome
27+
1. Fork the project
28+
2. Commit your changes
29+
3. Open a pull request
30+
31+

‎Get Image Metadata/img_meta.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import argparse
2+
import os
3+
from PIL import Image
4+
from PIL.ExifTags import TAGS
5+
import PIL
6+
7+
8+
def img_data(files):
9+
for file in files:
10+
11+
print(f"------------------{file} META DATA------------------")
12+
13+
if os.path.isfile(file):
14+
15+
try:
16+
# Read the image
17+
image = Image.open(file)
18+
19+
# Extract EXIF data
20+
exif_data = image.getexif()
21+
22+
# Iterating over EXIF data values
23+
for tag_id in exif_data:
24+
25+
# get the tag name
26+
tag = TAGS.get(tag_id, tag_id)
27+
28+
data = exif_data.get(tag_id)
29+
30+
# Try, except block
31+
try:
32+
# Check if instance is bytes
33+
if isinstance(data, bytes):
34+
# Decode bytes
35+
data = data.decode()
36+
37+
print(f"{tag:25}: {data}")
38+
39+
except UnicodeDecodeError:
40+
pass
41+
42+
print(f"----------------------------------------------------------")
43+
44+
except PIL.UnidentifiedImageError:
45+
print(f"Cannot Identify Image: {file}")
46+
print(f"----------------------------------------------------------")
47+
48+
else:
49+
print(f"No File Found: {file}")
50+
print(f"----------------------------------------------------------")
51+
52+
53+
def main():
54+
parser = argparse.ArgumentParser(description='EXTRACT METADATA IN IMAGES')
55+
56+
# Argument is for images files
57+
parser.add_argument('-f', dest='files', nargs='+', type=str, help='Image File(s)', required=True)
58+
59+
args = parser.parse_args()
60+
61+
# Get the files
62+
files = args.files
63+
64+
if files:
65+
img_data(files)
66+
67+
68+
if __name__ == '__main__':
69+
main()

‎Get Image Metadata/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pillow==8.1.0

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /