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

Tag values are ignored in JPEG XMP construction #5454

Closed
EpicWink opened this issue Apr 29, 2021 · 2 comments · Fixed by #5455
Closed

Tag values are ignored in JPEG XMP construction #5454

EpicWink opened this issue Apr 29, 2021 · 2 comments · Fixed by #5455
Labels

Comments

@EpicWink
Copy link

Tag values (not attributes) are ignored when constructing the XMP from JpegImageFile.getxmp.

My (panorama) image has XMP (APP1):

http://ns.adobe.com/xap/1.0/\x00
<?xpacket begin='\xef\xbb\xbf' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 11.88'>
  <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
    <rdf:Description rdf:about='' xmlns:GPano='http://ns.google.com/photos/1.0/panorama/'>
      <GPano:CroppedAreaImageHeightPixels>7985</GPano:CroppedAreaImageHeightPixels>
      <GPano:CroppedAreaImageWidthPixels>22944</GPano:CroppedAreaImageWidthPixels>
      <GPano:CroppedAreaLeftPixels>0</GPano:CroppedAreaLeftPixels>
      <GPano:CroppedAreaTopPixels>3487</GPano:CroppedAreaTopPixels>
      <GPano:FullPanoHeightPixels>11472</GPano:FullPanoHeightPixels>
      <GPano:FullPanoWidthPixels>22944</GPano:FullPanoWidthPixels>
      <GPano:ProjectionType>equirectangular</GPano:ProjectionType>
      <GPano:SourcePhotosCount>24</GPano:SourcePhotosCount>
      <GPano:StitchingSoftware>Hugin</GPano:StitchingSoftware>
      <GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>
    </rdf:Description>
  </rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>

Which currently Pillow resolves to:

{
    'RDF': {},
    'Description': {'about': ''},
    'CroppedAreaImageHeightPixels': {},
    'CroppedAreaImageWidthPixels': {},
    'CroppedAreaLeftPixels': {},
    'CroppedAreaTopPixels': {},
    'FullPanoHeightPixels': {},
    'FullPanoWidthPixels': {},
    'ProjectionType': {},
    'SourcePhotosCount': {},
    'StitchingSoftware': {},
    'UsePanoramaViewer': {},
}

You can replicate the above result with:

import types
from PIL.JpegImagePlugin import JpegImageFile

content = b"""<paste XML from above>"""
im = types.SimpleNamespace(_xmp={}, applist=[("APP1", content)])
print(JpegImageFile.getxmp(im))

My optimistic expectation would be:

{
    "xmpmeta": {
        "xmptk": "Image::ExifTool 11.88",
        "RDF": {
            "Description": {
                "about": "",
                "CroppedAreaImageHeightPixels": "7985",
                "CroppedAreaImageWidthPixels": "22944",
                "CroppedAreaLeftPixels": "0",
                "CroppedAreaTopPixels": "3487",
                "FullPanoHeightPixels": "11472",
                "FullPanoWidthPixels": "22944",
                "ProjectionType": "equirectangular",
                "SourcePhotosCount": "24",
                "StitchingSoftware": "Hugin",
                "UsePanoramaViewer": "True",
            },
        },
    },
}

My environment:
OS: Ubuntu 20.04.2
Python: 3.8.5
Pillow: 8.2.0

@radarhere
Copy link
Member

I've created PR #5455 - it should change the output to match your expectation.

@radarhere
Copy link
Member

Hi. Pillow 8.3.0 has now been released with updated format.

However, be aware that we've added a new requirement - as a security feature, you will have to install defusedxml to get it to work. See #5565 for more information

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