Mr. Goodie2Shoes Well-known member Sep 17, 2012 #1 Well, the title says it all, I am calling @primaryMedium which needs to be in HEX format... but it's giving me in rgb(x, y, z) format... Thanks!
Well, the title says it all, I am calling @primaryMedium which needs to be in HEX format... but it's giving me in rgb(x, y, z) format... Thanks!
Chris D XenForo developer Staff member Sep 17, 2012 #2 You might have to write a custom class for this... There are some colour related helpers but the end result is always RGB or RGBA. This one may help: Rich (BB code): function rgb2hex($rgb) { $hex = "#";$hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);$hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);$hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);return $hex; // returns the hex value including the number sign (#)}
You might have to write a custom class for this... There are some colour related helpers but the end result is always RGB or RGBA. This one may help: Rich (BB code): function rgb2hex($rgb) { $hex = "#";$hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);$hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);$hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);return $hex; // returns the hex value including the number sign (#)}
Mr. Goodie2Shoes Well-known member Sep 17, 2012 #3 Thanks! and what will be the input? rgb(x, y, z) or just x, y, z?
Chris D XenForo developer Staff member Sep 17, 2012 #4 Just x, y, z 255, 255, 255 would output #FFFFFF
Mr. Goodie2Shoes Well-known member Sep 17, 2012 #5 oh... forgot to mention, the input is actually an array... so you have to separate them by PHP: $rgb = str_replace(' ', '', $rgb) //just to make sure... $rgb = explode(',', $rgb);
oh... forgot to mention, the input is actually an array... so you have to separate them by PHP: $rgb = str_replace(' ', '', $rgb) //just to make sure... $rgb = explode(',', $rgb);
Mr. Goodie2Shoes Well-known member Sep 17, 2012 #7 bogus said: Why not just using a Converter? Click to expand... because i am fetching the style property automatically...
bogus said: Why not just using a Converter? Click to expand... because i am fetching the style property automatically...
Chris D XenForo developer Staff member Sep 17, 2012 #8 bogus said: Why not just using a Converter? Click to expand... I didn't ask, but I assume because he needs to do it programmatically for an add-on he's writing.
bogus said: Why not just using a Converter? Click to expand... I didn't ask, but I assume because he needs to do it programmatically for an add-on he's writing.