X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=rainbowstream%2Fimage.py;h=25afea776cc9c1fe8125db024c6296d5d9ccc56e;hb=25e5e7f4d1bf8690a1ba0f8b0b2ec65863f19eae;hp=12889b2ad503c91fb65651ffdec8044d4b1a1f01;hpb=1c50e2d1cbf7546f9c6ac1633ac0bfd471f31a1b;p=rainbowstream.git diff --git a/rainbowstream/image.py b/rainbowstream/image.py index 12889b2..25afea7 100644 --- a/rainbowstream/image.py +++ b/rainbowstream/image.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +from PIL import Image """ Convert values between RGB hex codes and xterm-256 color codes. @@ -321,6 +321,14 @@ def print_all(): print "Printed all codes." print "You can translate a hex or 0-255 code by providing an argument." +def hex_to_rgb(value): + value = value.lstrip('#') + lv = len(value) + return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3)) + +def rgb_to_hex(rgb): + return '#%02x%02x%02x' % rgb + def rgb2short(rgb): """ Find the closest xterm-256 approximation to the given RGB value. @param rgb: Hex code representing an RGB value, eg, 'abcdef' @@ -357,6 +365,10 @@ def rgb2short(rgb): RGB2SHORT_DICT, SHORT2RGB_DICT = _create_dicts() +def imgge_to_display(path): + i = Image.open(path) + return + #--------------------------------------------------------------------- if __name__ == '__main__': @@ -373,4 +385,4 @@ if __name__ == '__main__': else: short, rgb = rgb2short(arg) sys.stdout.write('RGB %s -> xterm color approx \033[38;5;%sm%s (%s)' % (arg, short, short, rgb)) - sys.stdout.write("\033[0m\n") \ No newline at end of file + sys.stdout.write("\033[0m\n")