Пример #1
0
class ImageTestCase(unittest.TestCase):
    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        img = Image(u'unicode.png')
        img.scale(0.5)
        img.write(u'unicode.jpg')

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')

    def test_scale_with_filtertype(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Catrom')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_catrom_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Cubic')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_cubic_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_digest = m.hexdigest()
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
        self.assertNotEqual(scale_with_filtertype_catrom_digest,
                            scale_with_filtertype_cubic_digest)

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        if sys.platform.lower() == 'darwin':
            img.font("/Library/Fonts/Arial.ttf")
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        img = Image((500, 300), 'red')
        self.assertEqual(img.width, 500)
        self.assertEqual(img.height, 300)
        img.scale(0.5)
        self.assertEqual(img.width, 250)
        self.assertEqual(img.height, 150)
Пример #2
0
class ImageTestCase(unittest.TestCase):
    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        if sys.version_info >= (3, ):
            img = Image('unicode.png')
        else:
            img = Image(unicode('unicode.png'))
        img.scale(0.5)
        if sys.version_info >= (3, ):
            img.write('unicode.jpg')
        else:
            img.write(unicode('unicode.jpg'))

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        im = Image((600, 400), 'red')
        im.scale(0.6)
        im.write('t.jpg')

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        im = Image((500, 300), 'red')
        self.assertEqual(im.width, 500)
        self.assertEqual(im.height, 300)
        im.scale(0.5)
        self.assertEqual(im.width, 250)
        self.assertEqual(im.height, 150)
Пример #3
0
class ImageTestCase(unittest.TestCase):

    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        if sys.version_info >= (3, ):
            img = Image('unicode.png')
        else:
            img = Image(unicode('unicode.png'))
        img.scale(0.5)
        if sys.version_info >= (3, ):
            img.write('unicode.jpg')
        else:
            img.write(unicode('unicode.jpg'))

    def test_nonarg(self):
        im = Image()

    def test_arg(self):
        im = Image((600, 400), 'red')

    def test_arg_float(self):
        im = Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        im = Image((600, 400), 'red')
        im.scale(0.6)
        im.write('t.jpg')

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        im = Image((500, 300), 'red')
        self.assertEqual(im.width, 500)
        self.assertEqual(im.height, 300)
        im.scale(0.5)
        self.assertEqual(im.width, 250)
        self.assertEqual(im.height, 150)
Пример #4
0
class ImageTestCase(unittest.TestCase):

    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        img = Image(u'unicode.png')
        img.scale(0.5)
        img.write(u'unicode.jpg')

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')

    def test_scale_with_filtertype(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Catrom')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_catrom_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Cubic')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_cubic_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_digest = m.hexdigest()
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_with_filtertype_cubic_digest)

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        if sys.platform.lower() == 'darwin':
            img.font("/Library/Fonts/Arial.ttf")
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        img = Image((500, 300), 'red')
        self.assertEqual(img.width, 500)
        self.assertEqual(img.height, 300)
        img.scale(0.5)
        self.assertEqual(img.width, 250)
        self.assertEqual(img.height, 150)