Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
duebbert opened this issue Jul 10, 2023 · 1 comment · Fixed by #7274
Closed

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

duebbert opened this issue Jul 10, 2023 · 1 comment · Fixed by #7274
Labels

Comments

@duebbert
Copy link

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

@radarhere radarhere changed the title getxmp() not returning any values for file containing XMP. getxmp() not returning any values for file containing XMP Jul 10, 2023
@radarhere radarhere added the JPEG label Jul 10, 2023
@radarhere
Copy link
Member

You have identified one problem, yes. The other problem was that we expected all attribute names to have a ":" in the name, and "xmptk" doesn't.

I've created PR #7274 to fix both of these. With that, your image returns

{'xmpmeta': {'xmptk': 'RICOH THETA SC Ver1.01', 'RDF': {'Description': {'about': '', 'ProjectionType': 'equirectangular', 'UsePanoramaViewer': 'True', 'CroppedAreaImageWidthPixels': '5376', 'CroppedAreaImageHeightPixels': '2688', 'FullPanoWidthPixels': '5376', 'FullPanoHeightPixels': '2688', 'CroppedAreaLeftPixels': '0', 'CroppedAreaTopPixels': '0', 'PosePitchDegrees': '2.8', 'PoseRollDegrees': '-1.3'}}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants