diff --git a/library/ZendPdf/Color/Html.php b/library/ZendPdf/Color/Html.php
index 94bf783..a9839e4 100644
--- a/library/ZendPdf/Color/Html.php
+++ b/library/ZendPdf/Color/Html.php
@@ -72,16 +72,26 @@ public function getComponents()
* Creates a ColorInterface object from the HTML representation.
*
* @param string $color May either be a hexidecimal number of the form
- * #rrggbb or one of the 140 well-known names (black, white, blue, etc.)
+ * #rrggbb, #rgb or one of the 140 well-known names (black, white, blue, etc.)
* @return ColorInterface
*/
public static function color($color)
{
- $pattern = '/^#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})$/';
+ $pattern = '/^#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})$|^#([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])$/';
if (preg_match($pattern, $color, $matches)) {
- $r = round((hexdec($matches[1]) / 255), 3);
- $g = round((hexdec($matches[2]) / 255), 3);
- $b = round((hexdec($matches[3]) / 255), 3);
+ if (strlen($matches[1]) === 2) {
+ $r = $matches[1];
+ $g = $matches[2];
+ $b = $matches[3];
+ } else {
+ $r = $matches[4].$matches[4];
+ $g = $matches[5].$matches[5];
+ $b = $matches[6].$matches[6];
+ }
+ $r = round((hexdec($r) / 255), 3);
+ $g = round((hexdec($g) / 255), 3);
+ $b = round((hexdec($b) / 255), 3);
+
if (($r == $g) && ($g == $b)) {
return new GrayScale($r);
} else {
diff --git a/tests/ZendPdf/Color/HtmlTest.php b/tests/ZendPdf/Color/HtmlTest.php
new file mode 100644
index 0000000..825c338
--- /dev/null
+++ b/tests/ZendPdf/Color/HtmlTest.php
@@ -0,0 +1,46 @@
+assertSame($components, Html::color($color)->getComponents());
+ }
+}