Python – DPI metadata is coordinates
Question:
I have a python script that gets the meta data of a file and puts it into a txt file. The script works and i got it from Here. My oly issue with itis that the DPI is shown as a coordinate and not a integer.
It looks like this (300,300)
and I would like it to look like this: 300
.
Here is my script as I have it:
image = Image.open(os.path.join(rootdir, file))
# extract other basic metadata
info_dict = {
"FileName": os.path.basename(image.filename),
"FileSize": os.path.getsize(image.filename),
"FilePath": pathlib.Path(image.filename).suffix,
"DPI": image.info['dpi'],
"Height": image.height,
"Width": image.width,
"Format": image.format,
"Mode": image.mode,
"Frames": getattr(image, "n_frames", 1)
}
line = ""
for label in range (1):
line += f"'{str(label)}'"
line = ",".join([str(val) for val in info_dict.values()])
print(line)
Answers:
info_dict = {
"FileName": os.path.basename(image.filename),
"FileSize": os.path.getsize(image.filename),
"FilePath": pathlib.Path(image.filename).suffix,
"DPI": image.info['dpi'][0],
"Height": image.height,
"Width": image.width,
"Format": image.format,
"Mode": image.mode,
"Frames": getattr(image, "n_frames", 1)
}
I have a python script that gets the meta data of a file and puts it into a txt file. The script works and i got it from Here. My oly issue with itis that the DPI is shown as a coordinate and not a integer.
It looks like this (300,300)
and I would like it to look like this: 300
.
Here is my script as I have it:
image = Image.open(os.path.join(rootdir, file))
# extract other basic metadata
info_dict = {
"FileName": os.path.basename(image.filename),
"FileSize": os.path.getsize(image.filename),
"FilePath": pathlib.Path(image.filename).suffix,
"DPI": image.info['dpi'],
"Height": image.height,
"Width": image.width,
"Format": image.format,
"Mode": image.mode,
"Frames": getattr(image, "n_frames", 1)
}
line = ""
for label in range (1):
line += f"'{str(label)}'"
line = ",".join([str(val) for val in info_dict.values()])
print(line)
info_dict = {
"FileName": os.path.basename(image.filename),
"FileSize": os.path.getsize(image.filename),
"FilePath": pathlib.Path(image.filename).suffix,
"DPI": image.info['dpi'][0],
"Height": image.height,
"Width": image.width,
"Format": image.format,
"Mode": image.mode,
"Frames": getattr(image, "n_frames", 1)
}