11
$\begingroup$

If I run some color processing function, like:

Blend[RGBColor /@ {"#DC4E00", "#000000", "#822250", "#FCC11B"}]

I get back a RGBColor object:

RGBColor[0.5901960784313726, 0.29901960784313725, 0.10490196078431373]

Is there a simple way to convert that RGBColor to an HTML string, like:

"#813912"
$\endgroup$
2

2 Answers 2

13
$\begingroup$

Seems like the function I was wanting was:

hexifyColor[color_RGBColor] := 
  StringJoin["#", IntegerString[Round[Level[color, 1]*255], 16, 2]]
$\endgroup$
6
$\begingroup$

It is there, deep down, but I'm too lazy to dig...

hexColor = StringCases[
    ExportString[Style[1, #], "HTMLFragment"], 
    "color:" ~~ color__ ~~ "\"" :> color
][[1]] &


hexColor@Blue
"#0000ff" 
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.