From 25e5e7f4d1bf8690a1ba0f8b0b2ec65863f19eae Mon Sep 17 00:00:00 2001 From: vunhat_minh Date: Thu, 5 Jun 2014 16:54:50 +0900 Subject: [PATCH] add func --- rainbowstream/image.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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") -- 2.25.1