-#! /usr/bin/env python
+from PIL import Image
""" Convert values between RGB hex codes and xterm-256 color codes.
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'
RGB2SHORT_DICT, SHORT2RGB_DICT = _create_dicts()
+def imgge_to_display(path):
+ i = Image.open(path)
+ return
+
#---------------------------------------------------------------------
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")