diff --git a/src/InitialAvatar.php b/src/InitialAvatar.php index fb26558..0058e07 100644 --- a/src/InitialAvatar.php +++ b/src/InitialAvatar.php @@ -108,7 +108,44 @@ public function background( $background ) { return $this; } - /** + /** + * Generate random color + * Stolen from here: https://stackoverflow.com/a/5614583/1103397 + * + * @return string Random hex color + */ + public function generateRandomColor() { + $color = []; + for ($i = 0; $i < 3; $i++){ + $color[] = str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT); + } + + return implode('', $color); + } + + /** + * Set random background color + * + * @return $this + */ + public function randBackground() { + $this->background($this->generateRandomColor()); + + return $this; + } + + /** + * Set random font color + * + * @return $this + */ + public function randColor() { + $this->color($this->generateRandomColor()); + + return $this; + } + + /** * Set the font color. * * @param string $color @@ -450,4 +487,4 @@ private function getFontByScript() { return $this->getFontFile(); } -} \ No newline at end of file +}