mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-09 06:44:45 +03:00
webp: add compression (lossless/lossy) to image info
This commit is contained in:
parent
30bee26b4a
commit
ec221cdbc5
|
@ -153,6 +153,7 @@ class WebPImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.size = size
|
self.size = size
|
||||||
|
self.info['compression'] = 'lossy' if lossy else 'lossless'
|
||||||
self.tile = [('webp', (0, 0) + size, 0,
|
self.tile = [('webp', (0, 0) + size, 0,
|
||||||
# Decoder params: rawmode, has_alpha, width, height.
|
# Decoder params: rawmode, has_alpha, width, height.
|
||||||
(mode, 1 if 'RGBA' == mode else 0, size[0], size[1]))]
|
(mode, 1 if 'RGBA' == mode else 0, size[0], size[1]))]
|
||||||
|
|
BIN
Tests/images/lossless-no-vp8x.webp
Normal file
BIN
Tests/images/lossless-no-vp8x.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 B |
BIN
Tests/images/lossless-with-vp8x.webp
Normal file
BIN
Tests/images/lossless-with-vp8x.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -72,6 +72,18 @@ class TestFileWebp(PillowTestCase):
|
||||||
target = hopper("RGB")
|
target = hopper("RGB")
|
||||||
self.assert_image_similar(image, target, 12)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -31,6 +31,7 @@ class TestFileWebpLossless(PillowTestCase):
|
||||||
self.assertEqual(image.mode, "RGB")
|
self.assertEqual(image.mode, "RGB")
|
||||||
self.assertEqual(image.size, (128, 128))
|
self.assertEqual(image.size, (128, 128))
|
||||||
self.assertEqual(image.format, "WEBP")
|
self.assertEqual(image.format, "WEBP")
|
||||||
|
self.assertEqual(image.info['compression'], 'lossless')
|
||||||
image.load()
|
image.load()
|
||||||
image.getdata()
|
image.getdata()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user