Same name in other branches
- 8.x-3.x advagg_css_minify/yui/CSSMin.inc \CSSmin::rgb_to_hex()
1 call to CSSmin::rgb_to_hex()
- CSSmin::hsl_to_hex in advagg_css_minify/
yui/ CSSMin.inc
File
-
advagg_css_minify/
yui/ CSSMin.inc, line 618
Class
Code
private function rgb_to_hex($matches) {
// Support for percentage values rgb(100%, 0%, 45%);
if ($this->index_of($matches[1], '%') >= 0) {
$rgbcolors = explode(',', str_replace('%', '', $matches[1]));
for ($i = 0; $i < count($rgbcolors); $i++) {
$rgbcolors[$i] = $this->round_number(floatval($rgbcolors[$i]) * 2.55);
}
}
else {
$rgbcolors = explode(',', $matches[1]);
}
// Values outside the sRGB color space should be clipped (0-255)
for ($i = 0; $i < count($rgbcolors); $i++) {
$rgbcolors[$i] = $this->clamp_number(intval($rgbcolors[$i], 10), 0, 255);
$rgbcolors[$i] = sprintf("%02x", $rgbcolors[$i]);
}
// Fix for issue #2528093
if (!preg_match('/[\\s\\,\\);\\}]/', $matches[2])) {
$matches[2] = ' ' . $matches[2];
}
return '#' . implode('', $rgbcolors) . $matches[2];
}