Browse files

Ajout de la conversion des couleurs RGB avec %

  • Loading branch information...
1 parent 5b73645 commit 2df3f71c05525882def1bd6b037e9dae3ba8e79e @NumEricR committed May 15, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 inc/functions.php
View
14 inc/functions.php
@@ -175,6 +175,8 @@ private function compress_css($css_to_compress,$lvl=0){
// Passage temporaire des codes hexa de 3 en 6 caractères (pour les conversions de couleurs)
$css_to_compress = preg_replace('#(:[^;]*\#)([a-fA-F\d])([a-fA-F\d])([a-fA-F\d])([^;]*;)#', '$1$2$2$3$3$4$4$5', $css_to_compress);
+ // Conversion des codes RGB utilisant des % en valeurs chiffrées
+ $css_to_compress = preg_replace_callback('#(:[^;]*rgb\()(\d{1,3})%[\s]*,[\s]*(\d{1,3})%[\s]*,[\s]*(\d{1,3})%(\)[^;]*;)#i', array($this, 'rgb_percent2value'), $css_to_compress);
// Conversion des codes couleurs
if ($this->get_option('colors_format') != 0) {
$css_to_compress = $this->convert_colors($css_to_compress);
@@ -205,7 +207,7 @@ private function convert_colors($css_to_compress) {
break;
case 2: // -> Hex
$css_to_compress = str_ireplace($keyword_named_colors, $hex_named_colors, $css_to_compress);
- $css_to_compress = preg_replace_callback('#(:[^;]*)rgb\((((\d){1,3}[\s]*%?,[\s]*){2}(\d){1,3}%?)\)([^;]*;)#', array($this, 'rgb2hex'), $css_to_compress);
+ $css_to_compress = preg_replace_callback('#(:[^;]*)rgb\((((\d){1,3}[\s]*,[\s]*){2}(\d){1,3})\)([^;]*;)#i', array($this, 'rgb2hex'), $css_to_compress);
break;
case 3: // -> RGB
$css_to_compress = str_ireplace($keyword_named_colors, $rgb_named_colors, $css_to_compress);
@@ -236,6 +238,16 @@ private function rgb2hex($matches) {
private function rgb_part2hex($rgb_part) {
return str_pad(dechex($rgb_part), 2, '0', STR_PAD_LEFT);
}
+
+ // Conversion d'un code RGB de pourcentages à valeurs chiffrées
+ private function rgb_percent2value($matches) {
+ return $matches[1] . $this->rgb_part_percent2value($matches[2]) . ',' . $this->rgb_part_percent2value($matches[3]) . ',' . $this->rgb_part_percent2value($matches[4]) . $matches[5];
+ }
+
+ // Conversion d'un des triplets RGB de pourcentage à une valeur chiffrée
+ private function rgb_part_percent2value($percent) {
+ return round($percent*255/100);
+ }
private function format_hex_color_values($matches) {
switch($this->get_option('hex_colors_format')) {

0 comments on commit 2df3f71

Please sign in to comment.