diff --git a/PIL/WebPImagePlugin.py b/PIL/WebPImagePlugin.py index fc86b4c0a..aadd5750d 100644 --- a/PIL/WebPImagePlugin.py +++ b/PIL/WebPImagePlugin.py @@ -153,6 +153,7 @@ class WebPImageFile(ImageFile.ImageFile): self.mode = mode self.size = size + self.info['compression'] = 'lossy' if lossy else 'lossless' self.tile = [('webp', (0, 0) + size, 0, # Decoder params: rawmode, has_alpha, width, height. (mode, 1 if 'RGBA' == mode else 0, size[0], size[1]))] diff --git a/Tests/images/lossless-no-vp8x.webp b/Tests/images/lossless-no-vp8x.webp new file mode 100644 index 000000000..9de86d8f0 Binary files /dev/null and b/Tests/images/lossless-no-vp8x.webp differ diff --git a/Tests/images/lossless-with-vp8x.webp b/Tests/images/lossless-with-vp8x.webp new file mode 100644 index 000000000..4de0a11c9 Binary files /dev/null and b/Tests/images/lossless-with-vp8x.webp differ diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 8c8313dd9..6c7ba98da 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -72,6 +72,18 @@ class TestFileWebp(PillowTestCase): target = hopper("RGB") self.assert_image_similar(image, target, 12) + def test_info_compression(self): + for name, compression in ( + ('flower2' , 'lossy'), + ('flower' , 'lossy'), + ('hopper' , 'lossy'), + ('lossless-no-vp8x' , 'lossless'), + ('lossless-with-vp8x', 'lossless'), + ('transparent' , 'lossy'), + ): + image = Image.open('Tests/images/%s.webp' % name) + self.assertEqual(image.info['compression'], compression) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_webp_lossless.py b/Tests/test_file_webp_lossless.py index 52a461a74..4996e367e 100644 --- a/Tests/test_file_webp_lossless.py +++ b/Tests/test_file_webp_lossless.py @@ -31,6 +31,7 @@ class TestFileWebpLossless(PillowTestCase): self.assertEqual(image.mode, "RGB") self.assertEqual(image.size, (128, 128)) self.assertEqual(image.format, "WEBP") + self.assertEqual(image.info['compression'], 'lossless') image.load() image.getdata()