Skip to content

Commit f5db6ab

Browse files
barryvanveenTorbenKoehn
authored andcommitted
fix Color::parseHexString for input of 6 characters (#6)
1 parent da8f082 commit f5db6ab

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Phim/Color.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,12 @@ public static function parseHexString($string)
13111311
hexdec($string[2].$string[2]),
13121312
hexdec($string[3].$string[3]) / 255
13131313
);
1314+
case 6:
1315+
return new RgbColor(
1316+
hexdec($string[0].$string[1]),
1317+
hexdec($string[2].$string[3]),
1318+
hexdec($string[4].$string[5])
1319+
);
13141320
}
13151321

13161322
return self::parseInt(hexdec($string));

tests/unit/ColorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function testFunctionStringConversion()
3232
self::assertEquals(51, $c->getGreen());
3333
self::assertEquals(120, $c->getBlue());
3434

35+
$c = Color::get('#6BBAA7')->toRgb();
36+
self::assertEquals(107, $c->getRed());
37+
self::assertEquals(186, $c->getGreen());
38+
self::assertEquals(167, $c->getBlue());
39+
3540
$c = Color::get('hsla(0.872664626rad, .4, 90%, 22.3%)')->toHsla();
3641
self::assertEquals(50, $c->getHue());
3742
self::assertEquals(.4, $c->getSaturation());

0 commit comments

Comments
 (0)