Ah. Right. Thanks. Does that exclude 0 too?
I was just trying to say that the values in your example will end in a invalid color for sRGB space.
Sorry if my limited English makes me be misunderstood.
I wasnât criticising, just asking. Actually, 0 can be either allowed or not with this:
use framework "Foundation"
on hexFromRGB(rgbList)
set {r, g, b} to rgbList
set d to (((r > 255) or (g > 255) or (b > 255)) as integer) * 255 + 1
return text 1 thru 6 of ((current application's NSString's stringWithFormat_("%08X", r div d * 65536 + g div d * 256 + b div d)) as text)
end hexFromRGB
{hexFromRGB({65535, 0, 29440}), hexFromRGB({255, 0, 115})}
1 Like
Yes, 0 is accepted.
Full black is {0, 0, 0}
Your construction for the return line is amazing!
Very nice handler, Nigel.
Thanks! Itâs based on Shaneâs and Jonasâs cracking of the problem, but implemented slightly differently.