Skip to content

Commit

Permalink
Add hex getter to Color (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erym974 authored Sep 28, 2022
1 parent 3668147 commit aec7fb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Color/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public function getOpacity(): float
return 1 - $this->alpha / 127;
}

public function getHex(): string
{
return sprintf('#%02x%02x%02x', $this->red, $this->green, $this->blue);
}

public function toArray(): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/Color/ColorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function getAlpha(): int;

public function getOpacity(): float;

public function getHex(): string;

/** @return array<string, int> */
public function toArray(): array;
}

0 comments on commit aec7fb1

Please sign in to comment.