I'm a beginner in Python and need to extract comments I made during fieldwork from a large amount of photos (>1000). They were made with an Iphone and were already converted to .JPG and stored in a single folder. The info I need is stored in the comments section (screenshot from "Get info" option on a macbook): Get info example
I parsed a lot of similar questions here and tried the following code below, but the metadata it returns doesn't include what I need.
Has anybody an idea how I could access the comments and store them in a dataframe/list?
from PIL import Image
from PIL.ExifTags import TAGS
# path to the image or video
imagename = ".../IMG_0001.JPG"
# read the image data using PIL
image = Image.open(imagename)
# extract EXIF data
exifdata = image.getexif()
# iterating over all EXIF data fields
for tag_id in exifdata:
# get the tag name, instead of human unreadable tag id
tag = TAGS.get(tag_id, tag_id)
data = exifdata.get(tag_id)
print(f"{tag:25}: {data}")
GPSInfo : 2180 ResolutionUnit : 2 ExifOffset : 264 Make : Apple Model : iPhone SE (2nd generation) Software : 15.3.1 Orientation : 6 DateTime : 2022:04:13 18:44:29 YCbCrPositioning : 1 XResolution : 72.0 YResolution : 72.0 HostComputer : iPhone SE (2nd generation)
CodePudding user response:
The data you are looking for is probably in the jpeg comment block, which is a different kind of metadata from EXIF data (all EXIF data is Metadata, but not all Metadata is EXIF data). It is not the best place to put important data because it is a very fragile location, as some programs will overwrite it. For example, older versions of Photoshop would overwrite it with File written by Adobe Photoshop #.##
.
A quick search pulls up this page which might have the code you need, assuming I picked the correct library (I'm not very knowledgeable about Python).