def convert(self): """Yields xterm color codes for each pixel in image """ (width, height) = self.img.size bgcolor = utils.term.bgcolor self.img.load() for y in range(height): for x in range(width): rgba = self.img.getpixel((x, y)) if len(rgba) == 4 and rgba[3] == 0: yield None elif len(rgba) == 3 or rgba[3] == 255: yield xterm256.rgb_to_xterm(*rgba[:3]) else: color = gf.Color.NewFromRgb(*[c / 255.0 for c in rgba]) rgba = gf.Color.AlphaBlend(color, bgcolor).rgb yield xterm256.rgb_to_xterm( *[int(c * 255.0) for c in rgba]) yield "EOL"
def __init__(self, color, *items): self.bg = xterm256.rgb_to_xterm(*parse_color(color)) self.fg = xterm256.rgb_to_xterm(*complement(color)) self.items = items
def __init__(self, color, *items): (r, g, b) = parse_color(color) self.color = xterm256.rgb_to_xterm(r, g, b) self.items = items
def html2xterm256(color): r, g, b = Color.HtmlToRgb(html_color) r = int(r * 255) g = int(g * 255) b = int(b * 255) return rgb_to_xterm(r, g, b)
def fg_start(color): return esc(38, 5, xterm256.rgb_to_xterm(*parse_color(color)))