projects
/
rainbowstream.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1c50e2d
)
add func
author
vunhat_minh
<vunhat_minh@dwango.co.jp>
Thu, 5 Jun 2014 07:54:50 +0000
(16:54 +0900)
committer
vunhat_minh
<vunhat_minh@dwango.co.jp>
Thu, 5 Jun 2014 07:54:50 +0000
(16:54 +0900)
rainbowstream/image.py
patch
|
blob
|
blame
|
history
diff --git
a/rainbowstream/image.py
b/rainbowstream/image.py
index 12889b2ad503c91fb65651ffdec8044d4b1a1f01..25afea776cc9c1fe8125db024c6296d5d9ccc56e 100644
(file)
--- 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.
""" 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."
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'
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()
RGB2SHORT_DICT, SHORT2RGB_DICT = _create_dicts()
+def imgge_to_display(path):
+ i = Image.open(path)
+ return
+
#---------------------------------------------------------------------
if __name__ == '__main__':
#---------------------------------------------------------------------
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))
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")