Reputation: 451
Need to convert RGB or HEX colors to "Long Int" for another program that uses this format. Not sure the specifics of the "Long Int" color format though.
It is possible to generate the "Long Int" values manually using this color-picker http://hide-inoki.com/en/soft/chunter/index.html but a php function would be preferred.
hexdec generates the correct "Long Int" for some HEX values ('FFFFFF', '2F2F2F') but not others ('123456').
Upvotes: 3
Views: 5072
Reputation: 21918
You should be able to use PHP's hexdec function.
hexdec('FFFFFF'): 16777215
hexdec('123456'): 1193046
etc.
Are you saying these values aren't correct? Or were you using dechex instead by mistake?
Update based on your comment which says that color "#123456" should be "5649426" in "Long Int" format:
5649426 in base 16 is 0x563412, so it's clear your format requires BGR instead of RGB.
So just build a "BGR" string from your "RGB" string first then feed it to hexdec:
$rgb = '123456';
$bgr = substr($rgb,4,2) . substr($rgb,2,2) . substr($rgb,0,2);
print hexdec($bgr);
yields 5649426
.
Upvotes: 7