Subversion Repositories php_utils

Compare Revisions

Regard whitespace Rev 53 → Rev 54

/trunk/color_utils.inc.php
106,16 → 106,18
function changeHueOfCSS($css_content, $h_shift=0, $s_shift=0, $v_shift=0) {
// TODO: also support rgb() and rgba() color references (and maybe also hsl/hsla and color names?)
// TODO: Bootstrap uses "--bs-link-color-rgb: 13,110,253;" which we must also accept
$css_content = preg_replace_callback('@(:|,)\\s*#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})@ismU',
$css_content = preg_replace('@(\\}\\s*)#@ismU', '\\1'.chr(1), $css_content);
$css_content = preg_replace('@(^\\s*)#@isU', '\\1'.chr(1), $css_content);
$css_content = preg_replace_callback('@#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})@ismU',
function ($x) use ($h_shift, $s_shift, $v_shift) {
if (strlen($x[2]) == 3) {
$r = hexdec($x[2][0].$x[2][0]);
$g = hexdec($x[2][1].$x[2][1]);
$b = hexdec($x[2][2].$x[2][2]);
if (strlen($x[1]) == 3) {
$r = hexdec($x[1][0].$x[1][0]);
$g = hexdec($x[1][1].$x[1][1]);
$b = hexdec($x[1][2].$x[1][2]);
} else {
$r = hexdec($x[2][0].$x[2][1]);
$g = hexdec($x[2][2].$x[2][3]);
$b = hexdec($x[2][4].$x[2][5]);
$r = hexdec($x[1][0].$x[1][1]);
$g = hexdec($x[1][2].$x[1][3]);
$b = hexdec($x[1][4].$x[1][5]);
}
list ($h,$s,$v) = RGB_TO_HSV($r, $g, $b);
$h = (float)$h;
125,8 → 127,9
$s = ($s + $s_shift); while ($s > 1) $s = 1; while ($s < 0) $s = 0;
$v = ($v + $v_shift); while ($v > 1) $v = 1; while ($v < 0) $v = 0;
list ($r,$g,$b) = HSV_TO_RGB($h, $s, $v);
return ':'.rgb2html($r,$g,$b);
return rgb2html($r,$g,$b);
}, $css_content);
$css_content = str_replace(chr(1), '#', $css_content);
return $css_content;
}
 
133,21 → 136,24
function invertColorsOfCSS($css_content) {
// TODO: also support rgb() and rgba() color references (and maybe also hsl/hsla and color names?)
// TODO: Bootstrap uses "--bs-link-color-rgb: 13,110,253;" which we must also accept
$css_content = preg_replace_callback('@(:|,)\\s*#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})@ismU',
$css_content = preg_replace('@(\\}\\s*)#@ismU', '\\1'.chr(1), $css_content);
$css_content = preg_replace('@(^\\s*)#@isU', '\\1'.chr(1), $css_content);
$css_content = preg_replace_callback('@#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})@ismU',
function ($x) {
if (strlen($x[2]) == 3) {
$r = hexdec($x[2][0].$x[2][0]);
$g = hexdec($x[2][1].$x[2][1]);
$b = hexdec($x[2][2].$x[2][2]);
if (strlen($x[1]) == 3) {
$r = hexdec($x[1][0].$x[1][0]);
$g = hexdec($x[1][1].$x[1][1]);
$b = hexdec($x[1][2].$x[1][2]);
} else {
$r = hexdec($x[2][0].$x[2][1]);
$g = hexdec($x[2][2].$x[2][3]);
$b = hexdec($x[2][4].$x[2][5]);
$r = hexdec($x[1][0].$x[1][1]);
$g = hexdec($x[1][2].$x[1][3]);
$b = hexdec($x[1][4].$x[1][5]);
}
$r = 255 - $r;
$g = 255 - $g;
$b = 255 - $b;
return ':'.rgb2html($r,$g,$b);
return rgb2html($r,$g,$b);
}, $css_content);
$css_content = str_replace(chr(1), '#', $css_content);
return $css_content;
}