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

Move getxmp() to JpegImageFile #5376

Merged
merged 3 commits into from Apr 1, 2021
Merged

Move getxmp() to JpegImageFile #5376

merged 3 commits into from Apr 1, 2021

Conversation

radarhere
Copy link
Member

Follow up to #5144

Moved getxmp() from Image to JpegImageFile, since the method fetches data from applist, which is a JpegImageFile property. Calling this method on a non-JPEG image would have caused an error.

@radarhere radarhere added the JPEG label Apr 1, 2021
@hugovk
Copy link
Member

hugovk commented Apr 1, 2021

Thanks! I was going to add something like this to "API Additions" in the release notes, let's include it here?

Image.getxmp
^^^^^^^^^^^^

A new method has been added to return an object with tag names and values to make it
easier to find what you're looking for, instead of giving the tag number to
:py:meth:`~PIL.Image.Image.getexif`.

For example::

    >>> from PIL import Image
    >>> with Image.open("xmp_test.jpg") as im:
    >>>    print(im.getxmp())
    {'RDF': {}, 'Description': {'Version': '10.4', 'ProcessVersion': '10.0', 'ConvertToGrayscale': 'False', 'CameraProfile': 'Adobe Standard', 'LookTable': 'E1095149FDB39D7A057BAB208837E2E1'}, 'History': {}, 'Seq': {}, 'li': {}, 'DerivedFrom': {'documentID': '8367D410E636EA95B7DE7EBA1C43A412', 'originalDocumentID': '8367D410E636EA95B7DE7EBA1C43A412'}, 'ToneCurve': {}, 'ToneCurveRed': {}, 'ToneCurveGreen': {}, 'ToneCurveBlue': {}, 'ToneCurvePV2012': {}, 'ToneCurvePV2012Red': {}, 'ToneCurvePV2012Green': {}, 'ToneCurvePV2012Blue': {}, 'RetouchAreas': {}, 'Masks': {}, 'RetouchInfo': {}, 'Look': {}, 'Group': {}, 'Alt': {}, 'Parameters': {}}

@hugovk hugovk added this to the 8.2.0 milestone Apr 1, 2021
@radarhere
Copy link
Member Author

I've added release notes - it's different from your version though.

It isn't actually pulling data from getexif(). That was just being discussed as a reference for how the API should act.

>>> from PIL import Image
>>> im = Image.open("Tests/images/xmp_test.jpg")
>>> im.getxmp()
{'RDF': {}, 'Description': {'Version': '10.4', 'ProcessVersion': '10.0', 'ConvertToGrayscale': 'False', 'CameraProfile': 'Adobe Standard', 'LookTable': 'E1095149FDB39D7A057BAB208837E2E1'}, 'History': {}, 'Seq': {}, 'li': {}, 'DerivedFrom': {'documentID': '8367D410E636EA95B7DE7EBA1C43A412', 'originalDocumentID': '8367D410E636EA95B7DE7EBA1C43A412'}, 'ToneCurve': {}, 'ToneCurveRed': {}, 'ToneCurveGreen': {}, 'ToneCurveBlue': {}, 'ToneCurvePV2012': {}, 'ToneCurvePV2012Red': {}, 'ToneCurvePV2012Green': {}, 'ToneCurvePV2012Blue': {}, 'RetouchAreas': {}, 'Masks': {}, 'RetouchInfo': {}, 'Look': {}, 'Group': {}, 'Alt': {}, 'Parameters': {}}
>>> dict(im.getexif())
{296: 2, 34665: 222, 271: 'Canon', 272: 'Canon EOS Rebel T6', 305: 'Adobe Photoshop Lightroom Classic 7.4 (Macintosh)', 306: '2018:10:27 16:20:29', 282: 300.0, 283: 300.0}

In the last half hour, I've figured out what's going on, and I'm writing this partly for my future self.

If you look at https://en.wikipedia.org/wiki/Extensible_Metadata_Platform#Embedding, XMP data can be stored in multiple locations

JPEG – Application segment 1 (0xFFE1) with segment header "http://ns.adobe.com/xap/1.0/\x00"
...
PNG – inside an "iTXt" text block with the keyword "XML:com.adobe.xmp"

We do use "XML:com.adobe.xmp" internally elsewhere in Pillow at one point.

The code in this method is just for JPEG images though. We could make this method read data more generally in the future, but that is not for today.

@hugovk
Copy link
Member

hugovk commented Apr 1, 2021

Great, thanks!

@hugovk hugovk merged commit ef5f294 into python-pillow:master Apr 1, 2021
@radarhere radarhere deleted the xmp branch April 1, 2021 12:38
@radarhere radarhere mentioned this pull request Apr 1, 2021
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 this pull request may close these issues.

None yet

2 participants