-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_metadata_modify.py
More file actions
70 lines (57 loc) · 2.53 KB
/
Copy pathimage_metadata_modify.py
File metadata and controls
70 lines (57 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
# Created on Friday, July 19 15:30:00 2024
# @author: mefamex
# project_name = "image-meta-dataset"
# project_version = "1.0.0"
# project_author = "Mefamex"
# project_date = "29.01.2025"
# project_description = "This is a project description"
# project_license = "MIT"
# project_repository = "https://github.com/Mefamex/image-meta-dataset"
# project_url = "https://mefamex.com/projects/image-meta-dataset"
# pip install piexif pillow
from PIL import Image
import os, piexif, piexif.helper
print("----------------------------------------\n"+os.getcwd())
print(os.path.dirname(os.path.realpath(__file__)))
print(os.path.dirname(os.path.abspath(__file__)))
print(__file__)
print("Pillow Version:", Image.__version__, "\n----------------------------------------\n")
from PIL import Image
import os, piexif, piexif.helper
def display_metadata(image_path):
if not os.path.exists(image_path):
print(f"Hata: {image_path} bulunamadı.")
return
image = Image.open(image_path)
exif_bytes = image.info.get("exif")
exif_data = piexif.load(exif_bytes) if exif_bytes else {"0th": {}, "Exif": {}, "GPS": {}, "Interop": {}, "1st": {}, "thumbnail": None}
print("Mevcut Metadata:")
for ifd in exif_data:
if exif_data[ifd] is None or isinstance(exif_data[ifd], bytes):
continue
for tag, value in exif_data[ifd].items():
try:
if isinstance(value, bytes):
value = value.decode(errors='ignore')
print(f"{piexif.TAGS[ifd][tag]['name']}: {value}")
except KeyError:
print(f"{tag}: {value}")
print("............................................")
def delete_image_metadata(image_path, output_path):
if not os.path.exists(image_path):
print(f"Hata: {image_path} bulunamadı.")
return
image = Image.open(image_path)
exif_bytes = image.info.get("exif")
exif_data = piexif.load(exif_bytes) if exif_bytes else {"0th": {}, "Exif": {}, "GPS": {}, "Interop": {}, "1st": {}, "thumbnail": None}
exif_bytes = piexif.dump(exif_data)
image.save(output_path, exif=exif_bytes)
print(f"{image_path} dosyasındaki metadata başarıyla silindi ve {output_path} dosyasına kaydedildi.")
print("............................................")
# Örnek Kullanım
image_path = "a.jpg"
output_path = "aa.jpg"
display_metadata(image_path)
delete_image_metadata(image_path, output_path)
display_metadata(output_path)