예제 #1
0
파일: Color.php 프로젝트: ju1ius/css-parser
 public function toHsl()
 {
     $mode = $this->mode;
     $channels = $this->channels;
     if (!$mode || $mode == 'hsl') {
         return $this;
     }
     if ($mode == 'hsla') {
         // If we don't need alpha channel, drop it
         if ($channels['a']->getValue() >= 1) {
             unset($this->channels['a']);
             $this->mode = 'hsl';
         }
         return $this;
     }
     $hsl = Util\Color::rgb2hsl($channels['r']->getValue(), $channels['g']->getValue(), $channels['b']->getValue(), isset($channels['a']) ? $channels['a']->getValue() : 1);
     $this->channels = array();
     $this->channels['h'] = new Dimension($hsl['h']);
     $this->channels['s'] = new Percentage($hsl['s']);
     $this->channels['l'] = new Percentage($hsl['l']);
     $this->mode = 'hsl';
     if (isset($hsl['a'])) {
         $this->channels['a'] = new Dimension($hsl['a']);
         $this->mode = 'hsla';
     }
     return $this;
 }