Skip to content

Commit c985b4f

Browse files
Correct stupid mistake in gexiv2 example
I was using GP_FILE_TYPE_METADATA instead of GP_FILE_TYPE_EXIF, which is of course not supported for jpeg files. Now the problem is passing a buffer to gexiv2.from_app1_segment.
1 parent 619535e commit c985b4f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

examples/read-exif-gexiv2.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ def get_file_exif_normal(camera, context, path):
5353
return md
5454

5555
def get_file_exif_metadata(camera, context, path):
56-
# this doesn't work on either of my Canon cameras
57-
# gphoto2 error -6: "Functionality not supported."
56+
# this doesn't work for me as from_app1_segment wants a pointer to a
57+
# single byte but then tries to read beyond it, causing a segfault
5858
folder, file_name = os.path.split(path)
5959
cam_file = camera.file_get(
60-
folder, file_name, gp.GP_FILE_TYPE_METADATA, context)
60+
folder, file_name, gp.GP_FILE_TYPE_EXIF, context)
6161
md = GExiv2.Metadata()
62-
md.from_app1_segment(cam_file.get_data_and_size())
62+
file_data = cam_file.get_data_and_size()
63+
data = bytes(file_data)
64+
md.from_app1_segment(data, len(data))
6365
return md
6466

6567
def main():
@@ -92,8 +94,8 @@ def main():
9294
print(key, ':', md.get_tag_string(key))
9395
break
9496
print()
95-
print('Exif data via GP_FILE_TYPE_METADATA')
96-
print('===================================')
97+
print('Exif data via GP_FILE_TYPE_EXIF')
98+
print('===============================')
9799
for path in files:
98100
if os.path.splitext(path)[1].lower() != '.jpg':
99101
continue

0 commit comments

Comments
 (0)