2017-02-16T15:41:13
Hex to RGB HTML Color Converter
#!/usr/bin/python
import sys
try:
hex_val = str(sys.argv[1])
except Exception as e:
sys.exit('Please provide a hex code as an argument (e.g. hex2rgb 333333).')
r = int(hex_val[0:2], 16)
g = int(hex_val[2:4], 16)
b = int(hex_val[4:6], 16)
print('{}, {}, {}'.format(r, g, b))
Append your ~/.bash_aliases with:
alias hex2rgb="~/bin/hex2rgb.py"
Load the new alias:
$ source ~/.bash_aliases
Now we're able to convert Hex to RGB from the command line:
$ hex2rgb e1e1e1
255, 255, 255