def test_parser(self): def roundtrip(format): im = hopper("L").resize((1000, 1000)) if format in ("MSP", "XBM"): im = im.convert("1") test_file = BytesIO() im.copy().save(test_file, format) data = test_file.getvalue() parser = ImageFile.Parser() parser.feed(data) imOut = parser.close() return im, imOut self.assert_image_equal(*roundtrip("BMP")) im1, im2 = roundtrip("GIF") self.assert_image_similar(im1.convert('P'), im2, 1) self.assert_image_equal(*roundtrip("IM")) self.assert_image_equal(*roundtrip("MSP")) if "zip_encoder" in codecs: try: # force multiple blocks in PNG driver ImageFile.MAXBLOCK = 8192 self.assert_image_equal(*roundtrip("PNG")) finally: ImageFile.MAXBLOCK = MAXBLOCK self.assert_image_equal(*roundtrip("PPM")) self.assert_image_equal(*roundtrip("TIFF")) self.assert_image_equal(*roundtrip("XBM")) self.assert_image_equal(*roundtrip("TGA")) self.assert_image_equal(*roundtrip("PCX")) if EpsImagePlugin.has_ghostscript(): im1, im2 = roundtrip("EPS") # This test fails on Ubuntu 12.04, PPC (Bigendian) It # appears to be a ghostscript 9.05 bug, since the # ghostscript rendering is wonky and the file is identical # to that written on ubuntu 12.04 x64 # md5sum: ba974835ff2d6f3f2fd0053a23521d4a # EPS comes back in RGB: self.assert_image_similar(im1, im2.convert('L'), 20) if "jpeg_encoder" in codecs: im1, im2 = roundtrip("JPEG") # lossy compression self.assert_image(im1, im2.mode, im2.size) self.assertRaises(IOError, lambda: roundtrip("PDF"))
def test_parser(self): def roundtrip(format): im = hopper("L").resize((1000, 1000), Image.NEAREST) if format in ("MSP", "XBM"): im = im.convert("1") test_file = BytesIO() im.copy().save(test_file, format) data = test_file.getvalue() parser = ImageFile.Parser() parser.feed(data) imOut = parser.close() return im, imOut assert_image_equal(*roundtrip("BMP")) im1, im2 = roundtrip("GIF") assert_image_similar(im1.convert("P"), im2, 1) assert_image_equal(*roundtrip("IM")) assert_image_equal(*roundtrip("MSP")) if features.check("zlib"): try: # force multiple blocks in PNG driver ImageFile.MAXBLOCK = 8192 assert_image_equal(*roundtrip("PNG")) finally: ImageFile.MAXBLOCK = MAXBLOCK assert_image_equal(*roundtrip("PPM")) assert_image_equal(*roundtrip("TIFF")) assert_image_equal(*roundtrip("XBM")) assert_image_equal(*roundtrip("TGA")) assert_image_equal(*roundtrip("PCX")) if EpsImagePlugin.has_ghostscript(): im1, im2 = roundtrip("EPS") # This test fails on Ubuntu 12.04, PPC (Bigendian) It # appears to be a ghostscript 9.05 bug, since the # ghostscript rendering is wonky and the file is identical # to that written on ubuntu 12.04 x64 # md5sum: ba974835ff2d6f3f2fd0053a23521d4a # EPS comes back in RGB: assert_image_similar(im1, im2.convert("L"), 20) if features.check("jpg"): im1, im2 = roundtrip("JPEG") # lossy compression assert_image(im1, im2.mode, im2.size) with pytest.raises(OSError): roundtrip("PDF")
def test_parser(self): def roundtrip(format): im = hopper("L").resize((1000, 1000)) if format in ("MSP", "XBM"): im = im.convert("1") file = BytesIO() im.save(file, format) data = file.getvalue() parser = ImageFile.Parser() parser.feed(data) imOut = parser.close() return im, imOut self.assert_image_equal(*roundtrip("BMP")) self.assert_image_equal(*roundtrip("GIF")) self.assert_image_equal(*roundtrip("IM")) self.assert_image_equal(*roundtrip("MSP")) if "zip_encoder" in codecs: try: # force multiple blocks in PNG driver ImageFile.MAXBLOCK = 8192 self.assert_image_equal(*roundtrip("PNG")) finally: ImageFile.MAXBLOCK = MAXBLOCK self.assert_image_equal(*roundtrip("PPM")) self.assert_image_equal(*roundtrip("TIFF")) self.assert_image_equal(*roundtrip("XBM")) self.assert_image_equal(*roundtrip("TGA")) self.assert_image_equal(*roundtrip("PCX")) if EpsImagePlugin.has_ghostscript(): im1, im2 = roundtrip("EPS") # This test fails on Ubuntu 12.04, PPC (Bigendian) It # appears to be a ghostscript 9.05 bug, since the # ghostscript rendering is wonky and the file is identical # to that written on ubuntu 12.04 x64 # md5sum: ba974835ff2d6f3f2fd0053a23521d4a # EPS comes back in RGB: self.assert_image_similar(im1, im2.convert('L'), 20) if "jpeg_encoder" in codecs: im1, im2 = roundtrip("JPEG") # lossy compression self.assert_image(im1, im2.mode, im2.size) self.assertRaises(IOError, lambda: roundtrip("PDF"))
def test_parser(self): def roundtrip(format): im = lena("L").resize((1000, 1000)) if format in ("MSP", "XBM"): im = im.convert("1") file = BytesIO() im.save(file, format) data = file.getvalue() parser = ImageFile.Parser() parser.feed(data) imOut = parser.close() return im, imOut self.assert_image_equal(*roundtrip("BMP")) self.assert_image_equal(*roundtrip("GIF")) self.assert_image_equal(*roundtrip("IM")) self.assert_image_equal(*roundtrip("MSP")) if "zip_encoder" in codecs: try: # force multiple blocks in PNG driver ImageFile.MAXBLOCK = 8192 self.assert_image_equal(*roundtrip("PNG")) finally: ImageFile.MAXBLOCK = MAXBLOCK self.assert_image_equal(*roundtrip("PPM")) self.assert_image_equal(*roundtrip("TIFF")) self.assert_image_equal(*roundtrip("XBM")) self.assert_image_equal(*roundtrip("TGA")) self.assert_image_equal(*roundtrip("PCX")) if EpsImagePlugin.has_ghostscript(): im1, im2 = roundtrip("EPS") # EPS comes back in RGB: self.assert_image_similar(im1, im2.convert('L'), 20) if "jpeg_encoder" in codecs: im1, im2 = roundtrip("JPEG") # lossy compression self.assert_image(im1, im2.mode, im2.size) self.assertRaises(IOError, lambda: roundtrip("PDF"))
def test_parser(self): def roundtrip(format): im = hopper("L").resize((1000, 1000)) if format in ("MSP", "XBM"): im = im.convert("1") file = BytesIO() im.save(file, format) data = file.getvalue() parser = ImageFile.Parser() parser.feed(data) imOut = parser.close() return im, imOut self.assert_image_equal(*roundtrip("BMP")) self.assert_image_equal(*roundtrip("GIF")) self.assert_image_equal(*roundtrip("IM")) self.assert_image_equal(*roundtrip("MSP")) if "zip_encoder" in codecs: try: # force multiple blocks in PNG driver ImageFile.MAXBLOCK = 8192 self.assert_image_equal(*roundtrip("PNG")) finally: ImageFile.MAXBLOCK = MAXBLOCK self.assert_image_equal(*roundtrip("PPM")) self.assert_image_equal(*roundtrip("TIFF")) self.assert_image_equal(*roundtrip("XBM")) self.assert_image_equal(*roundtrip("TGA")) self.assert_image_equal(*roundtrip("PCX")) if EpsImagePlugin.has_ghostscript(): im1, im2 = roundtrip("EPS") # EPS comes back in RGB: self.assert_image_similar(im1, im2.convert('L'), 20) if "jpeg_encoder" in codecs: im1, im2 = roundtrip("JPEG") # lossy compression self.assert_image(im1, im2.mode, im2.size) self.assertRaises(IOError, lambda: roundtrip("PDF"))
def setUp(self): if not EpsImagePlugin.has_ghostscript(): self.skipTest("Ghostscript not available")
import io import pytest from PIL import EpsImagePlugin, Image, features from .helper import assert_image_similar, hopper, skip_unless_feature HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript() # Our two EPS test files (they are identical except for their bounding boxes) FILE1 = "Tests/images/zero_bb.eps" FILE2 = "Tests/images/non_zero_bb.eps" # Due to palletization, we'll need to convert these to RGB after load FILE1_COMPARE = "Tests/images/zero_bb.png" FILE1_COMPARE_SCALE2 = "Tests/images/zero_bb_scale2.png" FILE2_COMPARE = "Tests/images/non_zero_bb.png" FILE2_COMPARE_SCALE2 = "Tests/images/non_zero_bb_scale2.png" # EPS test files with binary preview FILE3 = "Tests/images/binary_preview_map.eps" @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") def test_sanity(): # Regular scale with Image.open(FILE1) as image1: image1.load() assert image1.mode == "RGB"
from tester import * from PIL import Image, EpsImagePlugin import sys import io if not EpsImagePlugin.has_ghostscript(): skip() #Our two EPS test files (they are identical except for their bounding boxes) file1 = "Tests/images/zero_bb.eps" file2 = "Tests/images/non_zero_bb.eps" #Due to palletization, we'll need to convert these to RGB after load file1_compare = "Tests/images/zero_bb.png" file1_compare_scale2 = "Tests/images/zero_bb_scale2.png" file2_compare = "Tests/images/non_zero_bb.png" file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png" def test_sanity(): #Regular scale image1 = Image.open(file1) image1.load() assert_equal(image1.mode, "RGB") assert_equal(image1.size, (460, 352)) assert_equal(image1.format, "EPS") image2 = Image.open(file2) image2.load()
from tester import * from PIL import Image, EpsImagePlugin import sys import io if not EpsImagePlugin.has_ghostscript(): skip() #Our two EPS test files (they are identical except for their bounding boxes) file1 = "Tests/images/zero_bb.eps" file2 = "Tests/images/non_zero_bb.eps" #Due to palletization, we'll need to convert these to RGB after load file1_compare = "Tests/images/zero_bb.png" file1_compare_scale2 = "Tests/images/zero_bb_scale2.png" file2_compare = "Tests/images/non_zero_bb.png" file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png" def test_sanity(): #Regular scale image1 = Image.open(file1) image1.load() assert_equal(image1.mode, "RGB") assert_equal(image1.size, (460, 352)) assert_equal(image1.format, "EPS") image2 = Image.open(file2) image2.load() assert_equal(image2.mode, "RGB")
from .helper import unittest, PillowTestCase, hopper from PIL import Image, EpsImagePlugin import io HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript() # Our two EPS test files (they are identical except for their bounding boxes) file1 = "Tests/images/zero_bb.eps" file2 = "Tests/images/non_zero_bb.eps" # Due to palletization, we'll need to convert these to RGB after load file1_compare = "Tests/images/zero_bb.png" file1_compare_scale2 = "Tests/images/zero_bb_scale2.png" file2_compare = "Tests/images/non_zero_bb.png" file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png" # EPS test files with binary preview file3 = "Tests/images/binary_preview_map.eps" class TestFileEps(PillowTestCase): @unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available") def test_sanity(self): # Regular scale image1 = Image.open(file1) image1.load() self.assertEqual(image1.mode, "RGB") self.assertEqual(image1.size, (460, 352))