Skip to content

Commit

Permalink
Merge pull request #13 from renfordt/dev
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
renfordt authored Nov 24, 2024
2 parents a1a5c4d + 8bf40a7 commit da2a9c7
Show file tree
Hide file tree
Showing 26 changed files with 2,018 additions and 1,299 deletions.
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: Configure Git to avoid issues with line endings
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/vendor
/src/index.php
/.idea
composer.lock
composer.lock
.php-cs-fixer.cache
.phpunit.result.cache
93 changes: 78 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ install it to you project:
composer require renfordt/larvatar
```

## Upgrading to 2.0

Version 2.0 brings many breaking changes. Check the [Upgrade Guide](UPGRADING.md) to avoid any issues.

## Usage

The general usage is simple. Create a new Larvatar class, insert name and email and the avatar type you wish.
Expand All @@ -30,8 +34,17 @@ The general usage is simple. Create a new Larvatar class, insert name and email
use Renfordt\Larvatar\Enum\LarvatarTypes;
use Renfordt\Larvatar\Larvatar;

$larvatar = new Larvatar('Test Name', 'test@test.com', LarvatarTypes::InitialsAvatar);
// Larvatar::make($type, $name = '', $email = '')
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);

// Optional settings
$larvatar->setFont('Roboto,sans-serif', './font/Roboto-bold.ttf');
$larvatar->setSize(100);

// Get the SVG Code for embedding directly in your page
echo $larvatar->getImageHTML();

// if you need base64 encryption, currently this works only for InitialsAvatar
Expand All @@ -40,17 +53,39 @@ echo $larvatar->getImageHTML('base64');
echo $larvatar->getBase64();
```

There are currently eight different types of avatars available:
Alternatively you can create an instance of the `Name` class, which provides you more possibilities.

```php
\Renfordt\Larvatar\Enum\LarvatarTypes::InitialsAvatar; // Microsoft Teams like avatar with initials
\Renfordt\Larvatar\Enum\LarvatarTypes::Gravatar; // Gravatar
\Renfordt\Larvatar\Enum\LarvatarTypes::mp; // (Gravatar) MysticPerson, simple cartoon-style silhouette (default)
\Renfordt\Larvatar\Enum\LarvatarTypes::identicon; // (Gravatar) A geometric pattern based on a email hash
\Renfordt\Larvatar\Enum\LarvatarTypes::monsterid; // (Gravatar) A generated monster different colors and faces
\Renfordt\Larvatar\Enum\LarvatarTypes::wavatar; // (Gravatar) generated faces with differing features and backgrounds
\Renfordt\Larvatar\Enum\LarvatarTypes::retro; // (Gravatar) 8-bit arcade-style pixelated faces
\Renfordt\Larvatar\Enum\LarvatarTypes::robohash; // (Gravatar) A generated robot with different colors, faces, etc
$name = \Renfordt\Larvatar\Name::make('Test Name');

$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: $name
);
```

There are currently nine different types of avatars available:

```php
// 1) Microsoft Teams like avatar with initials
\Renfordt\Larvatar\Enum\LarvatarTypes::InitialsAvatar;
// 2) Identicons with more possibilities to adjust
\Renfordt\Larvatar\Enum\LarvatarTypes::IdenticonLarvatar;

// 3) Gravatar
\Renfordt\Larvatar\Enum\LarvatarTypes::Gravatar;
// 4) (Gravatar) MysticPerson, simple cartoon-style silhouette (default)
\Renfordt\Larvatar\Enum\LarvatarTypes::mp;
// 5) (Gravatar) A geometric pattern based on an email hash
\Renfordt\Larvatar\Enum\LarvatarTypes::identicon;
// 6) (Gravatar) A generated monster different colors and faces
\Renfordt\Larvatar\Enum\LarvatarTypes::monsterid;
// 7) (Gravatar) generated faces with differing features and backgrounds
\Renfordt\Larvatar\Enum\LarvatarTypes::wavatar;
// 8) (Gravatar) 8-bit arcade-style pixelated faces
\Renfordt\Larvatar\Enum\LarvatarTypes::retro;
// 9) (Gravatar) A generated robot with different colors, faces, etc
\Renfordt\Larvatar\Enum\LarvatarTypes::robohash;
```

## InitialsAvatar
Expand All @@ -62,7 +97,10 @@ hexagon and a square. Choose it by using the `setForm()` method. The input is ei
Enum `FormTypes`.

```PHP
$larvatar = new Larvatar('Your Name', type: LarvatarTypes::InitialsAvatar);
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);
$larvatar->initialsAvatar->setForm('circle');
$larvatar->initialsAvatar->setForm('square');
$larvatar->initialsAvatar->setForm('hexagon');
Expand All @@ -75,7 +113,10 @@ $larvatar->initialsAvatar->setForm(FormTypes::Hexagon);
If you are using the hexagon form, you have additionally the possibility to rotate the form:

```PHP
$larvatar = new Larvatar('Your Name', type: LarvatarTypes::InitialsAvatar);
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);
$larvatar->initialsAvatar->setForm(FormTypes::Hexagon);
$larvatar->initialsAvatar->setRotation(30);
```
Expand All @@ -88,15 +129,21 @@ and `setTextLightness()`. The parameter is a float with a value range `0` to `1`
is a lighter color.

```PHP
$larvatar = new Larvatar('Your Name', type: LarvatarTypes::InitialsAvatar);
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);
$larvatar->initialsAvatar->setBackgroundLightness(0.1);
$larvatar->initialsAvatar->setTextLightness(0.8);
```

Additionally, you can change the offset which will generate a different color.

```PHP
$larvatar = new Larvatar('Your Name', type: LarvatarTypes::InitialsAvatar);
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);
$larvatar->initialsAvatar->setOffset(4);
```

Expand All @@ -105,6 +152,22 @@ $larvatar->initialsAvatar->setOffset(4);
You can also change the font weight with the method `setFontWeight()`.

```PHP
$larvatar = new Larvatar('Your Name', type: LarvatarTypes::InitialsAvatar);
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);
$larvatar->initialsAvatar->setFontWeight('bold');
```

## Identicons (Larvatar Style)

```PHP
$larvatar = Larvatar::make(
type: LarvatarTypes::IdenticonLarvatar,
name: 'Test Name'
);

// optional settings
$larvatar->avatar->setSymmetry(false);
$larvatar->avatar->setPixels(8);
```
13 changes: 13 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
New:
```php
$larvatar = Larvatar::make(
type: LarvatarTypes::InitialsAvatar,
name: 'Test Name'
);
```


Old:
```php
$larvatar = new Larvatar('Test Name', 'test@test.com', LarvatarTypes::InitialsAvatar);
```
Binary file modified avatars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
"Renfordt\\Larvatar\\": "src/"
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": "^8.1",
"ext-gd": "*",
"meyfa/php-svg": "^0.14.0",
"renfordt/clamp": "^1.0"
"renfordt/clamp": "^1.0",
"renfordt/colors": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^10.5",
"orchestra/testbench": "^v8.22"
"orchestra/testbench": "^v8.22",
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^2.0"
},
"extra": {
"laravel": {
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.7"
services:
php:
build:
Expand Down
Loading

0 comments on commit da2a9c7

Please sign in to comment.