Skip to content

Commit

Permalink
Add optional encoding parameter to getImageHTML method
Browse files Browse the repository at this point in the history
The getImageHTML method in the Larvatar class now accepts an optional encoding parameter. When 'base64' is passed in as the encoding type, it generates a base64-encoded version of the image. In any other case, it generates the image without encoding.
  • Loading branch information
renfordt committed Apr 3, 2024
1 parent 9404b33 commit 0c2bf53
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Larvatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ public function __construct(string $name = '', string $email = '', int|LarvatarT
* Generates the HTML or SVG code directly for usage
* @return string HTML or SVG code
*/
public function getImageHTML(): string
public function getImageHTML(string $encoding = ''): string
{
if ($this->type == LarvatarTypes::InitialsAvatar) {
$initial_avatar = new InitialsAvatar($this->name);
if (isset($this->font) && $this->font != '' && $this->fontPath != '') {
$initial_avatar->setFont($this->font, $this->fontPath);
}
$initial_avatar->setSize($this->size);
return $initial_avatar->generate();
if ($encoding == 'base64') {
return '<img src="'.$initial_avatar->generate(encoding: $encoding).'" />';
} else {
return $initial_avatar->generate();
}
}

$gravatar = new Gravatar($this->email);
Expand Down

0 comments on commit 0c2bf53

Please sign in to comment.