Exemplo n.º 1
0
    def _generate_art(self, image, width, height):
        """
        Return an iterator that produces the ascii art.
        """
        image = image.resize((width, height), Image.ANTIALIAS).convert("RGB")
        pixels = list(image.getdata())

        for y in range(0, height - 1, 2):
            for x in range(width):
                i = y * width + x
                bg = rgb2short(*(pixels[i]))
                fg = rgb2short(*(pixels[i + width]))
                yield (fg, bg)
Exemplo n.º 2
0
    def _generate_art(self, image, width, height):
        """
        Return an iterator that produces the ascii art.
        """
        # Characters aren't square, so scale the output by the aspect ratio of a charater
        height = int(height * self._char_width / float(self._char_height))
        image = image.resize((width, height), Image.ANTIALIAS).convert("RGB")

        for (r, g, b) in image.getdata():
            greyscale = int(0.299 * r + 0.587 * g + 0.114 * b)
            ch = self._chars[int(greyscale / 255. * (len(self._chars) - 1) + 0.5)]
            yield (ch, rgb2short(r, g, b))
Exemplo n.º 3
0
def test_rgb2short():
    assert rgb2short(100, 100, 100) == 59