Read image XMP data in Python

Viewed 16546

Can I use PIL, like in this example?

I only need to read the data, and I'm looking for the easiest simplest way to do it (I can't install pyexiv).

edit: I don't want to believe that the only way to do this is with some library (python-xmp-toolkit, pyexiv2, ...) that needs Exempi and Boost. There must be another option!

6 Answers

Shout out to Chris Sherwood for the solution that I used. Came here to find a way to pull XMP data from DJI Drone Images. I too did not want to install Exempi. So, for posterity, I pulled these easier methods together for those people looking to extract values from XMP headers without a lot of hassle-

    # Extract XMP Data
    f = open(image_files[i], 'rb')
    d= f.read()
    xmp_start = d.find(b'<x:xmpmeta')
    xmp_end = d.find(b'</x:xmpmeta')
    xmp_str = d[xmp_start:xmp_end+12]

    # Extract Latitude
    search_str = b'Latitude="'
    value_start = xmp_str.find(search_str) + len(search_str)
    value_end = xmp_str.find(b'"',value_start)
    value = xmp_str[value_start:value_end]
    lat = value.decode('UTF-8')
Related