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