add func
[rainbowstream.git] / rainbowstream / image.py
index 12889b2ad503c91fb65651ffdec8044d4b1a1f01..25afea776cc9c1fe8125db024c6296d5d9ccc56e 100644 (file)
@@ -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")