Skip to content

Commit

Permalink
fix Color::parseHexString for input of 6 characters (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvanveen authored and TorbenKoehn committed Mar 31, 2018
1 parent da8f082 commit f5db6ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Phim/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,12 @@ public static function parseHexString($string)
hexdec($string[2].$string[2]),
hexdec($string[3].$string[3]) / 255
);
case 6:
return new RgbColor(
hexdec($string[0].$string[1]),
hexdec($string[2].$string[3]),
hexdec($string[4].$string[5])
);
}

return self::parseInt(hexdec($string));
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function testFunctionStringConversion()
self::assertEquals(51, $c->getGreen());
self::assertEquals(120, $c->getBlue());

$c = Color::get('#6BBAA7')->toRgb();
self::assertEquals(107, $c->getRed());
self::assertEquals(186, $c->getGreen());
self::assertEquals(167, $c->getBlue());

$c = Color::get('hsla(0.872664626rad, .4, 90%, 22.3%)')->toHsla();
self::assertEquals(50, $c->getHue());
self::assertEquals(.4, $c->getSaturation());
Expand Down

0 comments on commit f5db6ab

Please sign in to comment.