-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Inconsistent XMP data retrieval: Failure with specific JPEG files #7324
Comments
Hi. Looking at your traceback, I think we actually have a fix in progress for this already - #7274. Are you able to test that and see if it solves your problem? |
Thank you for the reply. How can I test this fix though, as it seems to be implemented in the source code? (I'm rather new to this, so apologies for any obvious questions). |
No worries, not a silly question at all. You could But the simplest, least invasive method would be So, for Option C, just run the following code and kindly report back if it works. from PIL import Image
def _getxmp(self, xmp_tags):
def get_name(tag):
return re.sub("^{[^}]+}", "", tag)
def get_value(element):
value = {get_name(k): v for k, v in element.attrib.items()}
children = list(element)
if children:
for child in children:
name = get_name(child.tag)
child_value = get_value(child)
if name in value:
if not isinstance(value[name], list):
value[name] = [value[name]]
value[name].append(child_value)
else:
value[name] = child_value
elif value:
if element.text:
value["text"] = element.text
else:
return element.text
return value
if ElementTree is None:
warnings.warn("XMP data cannot be read without defusedxml dependency")
return {}
else:
root = ElementTree.fromstring(xmp_tags)
return {get_name(root.tag): get_value(root)}
Image.Image._getxmp = _getxmp
image = Image.open("lib/filename_example_1.jpg")
raw_xmp_info = image.getxmp() |
Thank you for your reply. I have tested my JPEG using the code snippet you provided and it succesfully loads the XMP data. Therefore it works. |
What did you do?
I'm loading a .jpg image using Pillow in an attempt to extract the XMP metadata:
What did you expect to happen?
I'm expecting
getxmp()
to return a dictionary containing the image's XMP metadata:{'xmpmeta: {<metadata>}
.What actually happened?
Pillow can't extract the XMP metadata from the image:
What are your OS, Python and Pillow versions?
Additional information.
Printing
image.info
reveals:Due to confidentiality reasons, I can not provide the image that I'm trying to process. However, I will provide the anonomised XMP metadata of the image that causes the error (
filename_example_1.jpg
) and one which doesn't cause an error (filename_example_2.jpg
). This XMP metadata was extracted using https://www.imgonline.com.ua/. This shows that the metadata is present for both the working and the erroneous files.filename_example_1.jpg
(erroneous):filename_example_2.jpg
(successfully loaded by Pillow):If anyone is able to provide some insights into this bug, please let me know!
The text was updated successfully, but these errors were encountered: