diff --git a/Tests/images/xmp_test.jpg b/Tests/images/xmp_test.jpg new file mode 100644 index 000000000..4b9354f3a Binary files /dev/null and b/Tests/images/xmp_test.jpg differ diff --git a/Tests/test_image_getxmp.py b/Tests/test_image_getxmp.py index 965e07148..a2c400794 100644 --- a/Tests/test_image_getxmp.py +++ b/Tests/test_image_getxmp.py @@ -2,7 +2,8 @@ from PIL import Image def test_getxmp(): - im = Image.open("Tests/images/hopper.jpg") + im = Image.open("Tests/images/xmp_test.jpg") type_repr = repr(type(im.getxmp())) assert "dict" in type_repr + assert isinstance(im.getxmp()['Description'][0]['Version'], int) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 983580fc3..9b6c3d570 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1324,8 +1324,10 @@ class Image: Returns an object containing the xmp tags for a given image. :returns: XMP tags in an object. """ + if self._xmp is None: self._xmp = {} + for segment, content in self.applist: if segment == "APP1": marker, xmp_tags = content.rsplit(b"\x00", 1)