Пример #1
0
def resize_im(src, dst, size, factor=100):
    """resize with pystacia"""
    image = read(src)
    width, height = size
    scale = max(float(width) / image.width, float(height) / image.height)
    if scale > 1:
        image.rescale(factor=(scale + .001))
    elif scale < 0.9:
        image.rescale(factor=scale)
    scale = max(float(width) / image.width, float(height) / image.height)
    x = (image.width * scale - width) / 2
    y = (image.height * scale - height) / 2
    print image, scale, width, height, x, y
    image.resize(
            int(width), int(height),
            int(x), int(y),
          )
    if factor != 100:
        image.rescale(factor=factor / 100.)

    kwargs = {}
    fname, ext = os.path.splitext(src)
    if ext in ('.jpeg', '.jpg'):
        kwargs['quality'] = 85
        kwargs['strip'] = True

    image.write(dst, **kwargs)
Пример #2
0
def resize_im(src, dst, size, factor=100):
    """resize with pystacia"""
    image = read(src)
    width, height = size
    scale = max(float(width) / image.width, float(height) / image.height)
    if scale > 1:
        image.rescale(factor=(scale + .001))
    elif scale < 0.9:
        image.rescale(factor=scale)
    scale = max(float(width) / image.width, float(height) / image.height)
    x = (image.width * scale - width) / 2
    y = (image.height * scale - height) / 2
    print image, scale, width, height, x, y
    image.resize(
        int(width),
        int(height),
        int(x),
        int(y),
    )
    if factor != 100:
        image.rescale(factor=factor / 100.)

    kwargs = {}
    fname, ext = os.path.splitext(src)
    if ext in ('.jpeg', '.jpg'):
        kwargs['quality'] = 85
        kwargs['strip'] = True

    image.write(dst, **kwargs)
Пример #3
0
    def test_read(self):
        self.assertRaises(IOError, lambda: read('/non/existant.qwerty'))

        img = self.img

        tmpname = mkstemp()[1] + '.bmp'
        img.write(tmpname)

        img = read(tmpname)

        self.assertSequenceEqual(img.size, sample_size)
        self.assertEqual(img.type, sample_type)
        self.assertTrue(img.colorspace.name.endswith('rgb'))
        self.assertEqual(img.depth, 8)

        img.close()
Пример #4
0
    def test_show(self):
        img = self.img

        tmpname = img.show(no_gui=True)

        if 'png' in magick.get_formats():
            self.assertTrue(tmpname.endswith('.png'))
        else:
            self.assertTrue(tmpname.endswith('.bmp'))

        self.assertTrue(read(tmpname).is_same(img))
Пример #5
0
    def test_write(self):
        img = self.img

        tmpname = mkstemp()[1] + '.bmp'
        img.write(tmpname)

        img = read(tmpname)
        self.assertEqual(img.size, sample_size)
        self.assertTrue(img.colorspace.name.endswith('rgb'))
        self.assertEqual(img.type, sample_type)
        img.close()
Пример #6
0
    def test(self):
        import pystacia
        from pystacia import image

        with catch_warnings(record=True) as w:
            simplefilter('always')

            self.assertTrue(
                image.blank(30, 30).is_same(pystacia.blank(30, 30)))

            self.assertTrue('blank' in w[-1].message.args[0])

            if lena_available():
                self.assertTrue(image.lena().is_same(pystacia.lena()))
                self.assertTrue('lena' in w[-1].message.args[0])

            tmpname = mkstemp()[1] + '.bmp'
            img = sample()
            img.write(tmpname)

            self.assertTrue(
                pystacia.read(tmpname).is_same(image.read(tmpname)))
            self.assertTrue('read' in w[-1].message.args[0])

            self.assertTrue(
                pystacia.read_blob(img.get_blob('bmp')).is_same(
                    image.read_blob(img.get_blob('bmp'))))

            self.assertTrue(
                pystacia.read_raw(**img.get_raw('rgb')).is_same(
                    image.read_raw(**img.get_raw('rgb'))))

            img.close()

            for symbol in [
                    'magick_logo', 'wizard', 'netscape', 'granite', 'rose'
            ]:
                self.assertTrue(
                    getattr(image,
                            symbol)().is_same(getattr(pystacia, symbol)()))
                self.assertTrue(symbol in w[-1].message.args[0])

            self.assertIsInstance(pystacia.Image(), image.Image)

            names = [
                'composites', 'types', 'filters', 'colorspaces',
                'compressions', 'axes'
            ]
            for name in names:
                self.assertEqual(
                    getattr(pystacia, name).x,
                    getattr(image, name).x)
                self.assertTrue(name in w[-1].message.args[0])
Пример #7
0
    def test(self):
        import pystacia
        from pystacia import image

        with catch_warnings(record=True) as w:
            simplefilter('always')

            self.assertTrue(image.blank(30, 30).
                            is_same(pystacia.blank(30, 30)))

            self.assertTrue('blank' in w[-1].message.args[0])

            if lena_available():
                self.assertTrue(image.lena().is_same(pystacia.lena()))
                self.assertTrue('lena' in w[-1].message.args[0])

            tmpname = mkstemp()[1] + '.bmp'
            img = sample()
            img.write(tmpname)

            self.assertTrue(pystacia.read(tmpname).
                            is_same(image.read(tmpname)))
            self.assertTrue('read' in w[-1].message.args[0])

            self.assertTrue(pystacia.read_blob(img.get_blob('bmp')).
                            is_same(image.read_blob(img.get_blob('bmp'))))

            self.assertTrue(pystacia.read_raw(**img.get_raw('rgb')).
                            is_same(image.read_raw(**img.get_raw('rgb'))))

            img.close()

            for symbol in ['magick_logo', 'wizard',
                           'netscape', 'granite', 'rose']:
                self.assertTrue(getattr(image, symbol)().
                                is_same(getattr(pystacia, symbol)()))
                self.assertTrue(symbol in w[-1].message.args[0])

            self.assertIsInstance(pystacia.Image(), image.Image)

            names = ['composites', 'types', 'filters', 'colorspaces',
                     'compressions', 'axes']
            for name in names:
                self.assertEqual(getattr(pystacia, name).x,
                                 getattr(image, name).x)
                self.assertTrue(name in w[-1].message.args[0])
Пример #8
0
def resize_im(src, dst, size, factor=100):
    """resize with pystacia"""
    image = read(src)
    width, height = size
    scale = max(float(width) / image.width, float(height) / image.height)
    if scale > 1:
        image.rescale(factor=(scale + .001))
    elif scale < 0.9:
        image.rescale(factor=scale)
    scale = max(float(width) / image.width, float(height) / image.height)
    x = (image.width * scale - width) / 2
    y = (image.height * scale - height) / 2
    image.resize(
        int(width), int(height),
        int(x), int(y),
    )
    if factor != 100:
        image.rescale(factor=factor / 100.)
    image.write(dst)
Пример #9
0
def resize_im(src, dst, size, factor=100):
    """resize with pystacia"""
    image = read(src)
    width, height = size
    scale = max(float(width) / image.width, float(height) / image.height)
    if scale > 1:
        image.rescale(factor=(scale + .001))
    elif scale < 0.9:
        image.rescale(factor=scale)
    scale = max(float(width) / image.width, float(height) / image.height)
    x = (image.width * scale - width) / 2
    y = (image.height * scale - height) / 2
    image.resize(
        int(width),
        int(height),
        int(x),
        int(y),
    )
    if factor != 100:
        image.rescale(factor=factor / 100.)
    image.write(dst)
Пример #10
0
from pystacia.image import read


image = read('example.png')

image.rescale(320, 240)
image.rotate(30)
image.show()
image.write('output.jpeg')

# free acquired resources
image.close()
Пример #11
0
from pystacia.image import read

image = read('example.png')

image.rescale(320, 240)
image.rotate(30)
image.show()
image.write('output.jpeg')

# free acquired resources
image.close()