10
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by J. M. is away Mar 22 '17 at 3:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

11
$\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.