Pillow/Tests/test_image_quantize.py

40 lines
907 B
Python
Raw Normal View History

from helper import unittest, PillowTestCase, hopper
from PIL import Image
2014-06-10 13:10:47 +04:00
class TestImageQuantize(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_sanity(self):
im = hopper()
2014-06-10 13:10:47 +04:00
im = im.quantize()
self.assert_image(im, "P", im.size)
im = hopper()
im = im.quantize(palette=hopper("P"))
2014-06-10 13:10:47 +04:00
self.assert_image(im, "P", im.size)
2014-06-10 13:10:47 +04:00
def test_octree_quantize(self):
im = hopper()
2014-06-10 13:10:47 +04:00
im = im.quantize(100, Image.FASTOCTREE)
self.assert_image(im, "P", im.size)
2014-03-26 08:42:04 +04:00
2014-06-10 13:10:47 +04:00
assert len(im.getcolors()) == 100
def test_rgba_quantize(self):
im = hopper('RGBA')
2014-06-10 13:10:47 +04:00
im.quantize()
self.assertRaises(Exception, lambda: im.quantize(method=0))
2015-08-22 16:03:11 +03:00
def test_quantize(self):
im = Image.open('Tests/images/caption_6_33_22.png')
im.convert('RGB').quantize().convert('RGB')
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()
# End of file