Optimize the function of colortoHex(str)

Optimize the function converting color parameter from rgb(x,x,x) to
#XXXXXX