Exemple #1
0
 /**
  * Returns the 'value' channel of @color in the HSV space
  *
  * @param ColorNode $color
  * @return string
  */
 public function hsvvalue(Node $color)
 {
     if (!$color instanceof ColorNode) {
         return $color;
     }
     $hsv = $color->toHSV();
     return new DimensionNode(Math::round($hsv['v'] * 100), '%');
 }
Exemple #2
0
 /**
  * @covers       round
  * @dataProvider getDataForRoundTest
  */
 public function testRound($value, $precision, $expected)
 {
     $this->assertEquals($expected, Math::round($value, $precision), sprintf('Rounding of "%s" with precision "%s" works', $value, $precision));
 }
Exemple #3
0
 /**
  * Returns the color as HEX string (when transparency present, in RGBA model)
  *
  * @param boolean $compress Compress the color?
  * @param boolean $canShorten Can the color be shortened if possible?
  * @return string
  */
 public function toString($compress = false, $canShorten = false)
 {
     if ($this->isTransparentKeyword) {
         return 'transparent';
     }
     if ($this->originalForm) {
         return $this->originalForm;
     }
     $alpha = Math::toFixed($this->alpha + 2.0E-16, 8);
     if ($alpha < 1) {
         $fixedRGB = $this->getFixedRGB();
         return sprintf('rgba(%s)', join($compress ? ',' : ', ', [$fixedRGB[0], $fixedRGB[1], $fixedRGB[2], Math::clean($this->clamp($alpha, 1))]));
     }
     // prevent named colors
     if ($this->keyword) {
         return $this->keyword;
     }
     $color = [];
     foreach ($this->getFixedRgb() as $i) {
         $color[] = str_pad(dechex(Math::round($i)), 2, '0', STR_PAD_LEFT);
     }
     $color = join('', $color);
     // convert color to short format
     if ($canShorten && $color[0] === $color[1] && $color[2] === $color[3] && $color[4] === $color[5]) {
         $color = $color[0] . $color[2] . $color[4];
     }
     $color = '#' . $color;
     return $color;
 }