Skip to content

Commit 129d291

Browse files
committed
rgbToRgba()
1 parent d30a1da commit 129d291

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

PHPWebDriver/Support/WebDriverColor.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ class PHPWebDriver_Support_Color {
1717
public function __construct($color) {
1818
$this->_color = $color;
1919

20-
$a = '1.0';
21-
22-
// rgb
20+
2321
if (substr($color, 0, 3) === "rgb" && substr($color, 3, 4) !== "a") {
22+
// rgb
2423
$pattern = '/^\s*rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)\s*$/';
25-
preg_match($pattern, $color, $matches);
24+
} elseif (substr($color, 0, 4) === "rgba") {
25+
// rgba
26+
$pattern = '/^\s*rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0\.\d+)\s*\)\s*$/';
2627
}
2728

29+
preg_match($pattern, $color, $matches);
30+
$a = 1;
2831
if (count($matches) != 0) {
29-
$a = '1.0';
3032
if (count($matches) == 5) {
3133
$a = $matches[4];
3234
}
@@ -45,7 +47,7 @@ public function rgb() {
4547
}
4648

4749
public function rgba() {
48-
50+
return 'rgba(' . $this->red . ', ' . $this->green . ', ' . $this->blue . ', ' . $this->alpha . ')';
4951
}
5052

5153
public function hex() {}

0 commit comments

Comments
 (0)