Skip to content

getxmp() not returning any values for file containing XMP #7273

Closed
@duebbert

Description

@duebbert

Attached is an example file with XMP data.

Exiftool shows the XMP data correctly:

# exiftool -v test.jpg
[...]
JPEG APP1 (1132 bytes):
  + [XMP directory, 1103 bytes]
  | XMPToolkit = RICOH THETA SC Ver1.01
  | ProjectionType = equirectangular
  | UsePanoramaViewer = True
  | CroppedAreaImageWidthPixels = 5376
  | CroppedAreaImageHeightPixels = 2688
  | FullPanoWidthPixels = 5376
  | FullPanoHeightPixels = 2688
  | CroppedAreaLeftPixels = 0
  | CroppedAreaTopPixels = 0
  | PosePitchDegrees = 2.8
  | PoseRollDegrees = -1.3
[...]

But when opening it with Pillow (defusedxml is installed), it returns no XMP Data:

>>> from PIL import Image
>>> img = Image.open("test.jpg")
>>> img.getxmp()
{}
>>> 

What did you expect to happen?

It should return the XMP data of the file.

What actually happened?

It returned an empty dict.

Digging into the code, I believe the problem is that the "APP1" segment seems to be padded with several b"\x00" so the getxmp() function doesn't find the marker due to rsplit being used. But there might be other issues:

>>> img = Image.open("test.jpg")
>>> for segment, content in img.applist:
...     if segment == "APP1" and b"ns.adobe.com" in content:
...             print(content)
... 
b'http://ns.adobe.com/xap/1.0/\x00<?xpacket begin="\xef\xbb\xbf" id="W5M0MpCehiHzreSzNTczkc9d"?>\n<x:xmpmeta 
xmlns:x="adobe:ns:meta/" xmptk="RICOH THETA SC Ver1.01">\n  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-
syntax-ns#">\n    <rdf:Description rdf:about="" xmlns:GPano="http://ns.google.com/photos/1.0/panorama/">\n      
<GPano:ProjectionType>equirectangular</GPano:ProjectionType>\n      
<GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>\n      
<GPano:CroppedAreaImageWidthPixels>5376</GPano:CroppedAreaImageWidthPixels>\n      
<GPano:CroppedAreaImageHeightPixels>2688</GPano:CroppedAreaImageHeightPixels>\n      
<GPano:FullPanoWidthPixels>5376</GPano:FullPanoWidthPixels>\n      
<GPano:FullPanoHeightPixels>2688</GPano:FullPanoHeightPixels>\n      
<GPano:CroppedAreaLeftPixels>0</GPano:CroppedAreaLeftPixels>\n      
<GPano:CroppedAreaTopPixels>0</GPano:CroppedAreaTopPixels>\n      
<GPano:PosePitchDegrees>2.8</GPano:PosePitchDegrees>\n      <GPano:PoseRollDegrees>-1.3</GPano:PoseRollDegrees>\n    
</rdf:Description>\n  </rdf:RDF>\n</x:xmpmeta>\n<?xpacket end="r"?>\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00'
>>> 

What are your OS, Python and Pillow versions?

  • OS: Linux Fedora 38
  • Python: 3.11.4
  • Pillow: 10.0.0

test

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions