def test_safeblock(self): if "zip_encoder" not in codecs: self.skipTest("PNG (zlib) encoder not available") im1 = hopper() try: ImageFile.SAFEBLOCK = 1 im2 = fromstring(tostring(im1, "PNG")) finally: ImageFile.SAFEBLOCK = SAFEBLOCK self.assert_image_equal(im1, im2)
def test_fileio(self): class DumbFile: def __init__(self, data): self.data = data def read(self, bytes=None): assert (bytes is None) return self.data def close(self): pass im1 = lena() io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM"))) im2 = Image.open(io) self.assert_image_equal(im1, im2)
def test_fileio(self): class DumbFile: def __init__(self, data): self.data = data def read(self, bytes=None): assert(bytes is None) return self.data def close(self): pass im1 = lena() io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM"))) im2 = Image.open(io) self.assert_image_equal(im1, im2)
from helper import unittest, PillowTestCase, fromstring, tostring from PIL import Image CODECS = dir(Image.core) FILENAME = "Tests/images/hopper.jpg" DATA = tostring(Image.open(FILENAME).resize((512, 512)), "JPEG") def draft(mode, size): im = fromstring(DATA) im.draft(mode, size) return im class TestImageDraft(PillowTestCase): def setUp(self): if "jpeg_encoder" not in CODECS or "jpeg_decoder" not in CODECS: self.skipTest("jpeg support not available") def test_size(self): self.assertEqual(draft("RGB", (512, 512)).size, (512, 512)) self.assertEqual(draft("RGB", (256, 256)).size, (256, 256)) self.assertEqual(draft("RGB", (128, 128)).size, (128, 128)) self.assertEqual(draft("RGB", (64, 64)).size, (64, 64)) self.assertEqual(draft("RGB", (32, 32)).size, (64, 64)) def test_mode(self): self.assertEqual(draft("1", (512, 512)).mode, "RGB") self.assertEqual(draft("L", (512, 512)).mode, "L") self.assertEqual(draft("RGB", (512, 512)).mode, "RGB")
def draft_roundtrip(self, in_mode, in_size, req_mode, req_size): im = Image.new(in_mode, in_size) data = tostring(im, 'JPEG') im = fromstring(data) im.draft(req_mode, req_size) return im
from helper import unittest, PillowTestCase, tearDownModule, fromstring, tostring from PIL import Image codecs = dir(Image.core) filename = "Tests/images/lena.jpg" data = tostring(Image.open(filename).resize((512, 512)), "JPEG") def draft(mode, size): im = fromstring(data) im.draft(mode, size) return im class TestImageDraft(PillowTestCase): def setUp(self): if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs: self.skipTest("jpeg support not available") def test_size(self): self.assertEqual(draft("RGB", (512, 512)).size, (512, 512)) self.assertEqual(draft("RGB", (256, 256)).size, (256, 256)) self.assertEqual(draft("RGB", (128, 128)).size, (128, 128)) self.assertEqual(draft("RGB", (64, 64)).size, (64, 64)) self.assertEqual(draft("RGB", (32, 32)).size, (64, 64)) def test_mode(self): self.assertEqual(draft("1", (512, 512)).mode, "RGB") self.assertEqual(draft("L", (512, 512)).mode, "L")
from helper import unittest, PillowTestCase, fromstring, tostring from PIL import Image codecs = dir(Image.core) filename = "Tests/images/lena.jpg" data = tostring(Image.open(filename).resize((512, 512)), "JPEG") def draft(mode, size): im = fromstring(data) im.draft(mode, size) return im class TestImageDraft(PillowTestCase): def setUp(self): if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs: self.skipTest("jpeg support not available") def test_size(self): self.assertEqual(draft("RGB", (512, 512)).size, (512, 512)) self.assertEqual(draft("RGB", (256, 256)).size, (256, 256)) self.assertEqual(draft("RGB", (128, 128)).size, (128, 128)) self.assertEqual(draft("RGB", (64, 64)).size, (64, 64)) self.assertEqual(draft("RGB", (32, 32)).size, (64, 64)) def test_mode(self): self.assertEqual(draft("1", (512, 512)).mode, "RGB") self.assertEqual(draft("L", (512, 512)).mode, "L") self.assertEqual(draft("RGB", (512, 512)).mode, "RGB")