Skip to content

Commit aec7fb1

Browse files
authored
Add hex getter to Color (#384)
1 parent 3668147 commit aec7fb1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Color/Color.php

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function getOpacity(): float
4444
return 1 - $this->alpha / 127;
4545
}
4646

47+
public function getHex(): string
48+
{
49+
return sprintf('#%02x%02x%02x', $this->red, $this->green, $this->blue);
50+
}
51+
4752
public function toArray(): array
4853
{
4954
return [

src/Color/ColorInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public function getAlpha(): int;
1616

1717
public function getOpacity(): float;
1818

19+
public function getHex(): string;
20+
1921
/** @return array<string, int> */
2022
public function toArray(): array;
2123
}

0 commit comments

Comments
 (0)