{"id":18592488,"url":"https://github.com/renfordt/larvatar","last_synced_at":"2025-04-10T15:31:57.960Z","repository":{"id":65354033,"uuid":"590063407","full_name":"renfordt/larvatar","owner":"renfordt","description":"Larvatar is a PHP package for different types of avatars","archived":false,"fork":false,"pushed_at":"2025-03-17T10:44:57.000Z","size":519,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T23:41:23.304Z","etag":null,"topics":["avatar","gravatar","identicon","initials","initials-avatar","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renfordt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-17T15:22:55.000Z","updated_at":"2025-01-18T23:28:05.000Z","dependencies_parsed_at":"2024-03-13T11:48:20.979Z","dependency_job_id":"d077a1bb-9b0b-40eb-b55c-2dd1c8c3a636","html_url":"https://github.com/renfordt/larvatar","commit_stats":{"total_commits":84,"total_committers":2,"mean_commits":42.0,"dds":"0.11904761904761907","last_synced_commit":"4688c002e64e6edcfd4f98d3c52aa05db54f44f3"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfordt%2Flarvatar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfordt%2Flarvatar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfordt%2Flarvatar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfordt%2Flarvatar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renfordt","download_url":"https://codeload.github.com/renfordt/larvatar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248243465,"owners_count":21071054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avatar","gravatar","identicon","initials","initials-avatar","laravel","php"],"created_at":"2024-11-07T01:08:53.447Z","updated_at":"2025-04-10T15:31:57.950Z","avatar_url":"https://github.com/renfordt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Larvatar\r\n\r\n[![Badge](http://img.shields.io/badge/source-renfordt/Larvatar-blue.svg)](https://github.com/renfordt/Larvatar)\r\n[![Packagist Version](https://img.shields.io/packagist/v/renfordt/larvatar?include_prereleases)](https://packagist.org/packages/renfordt/larvatar/)\r\n![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/renfordt/larvatar/php)\r\n![GitHub License](https://img.shields.io/github/license/renfordt/Larvatar)\r\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/renfordt/Larvatar/test.yml?logo=github)\r\n[![Code Climate coverage](https://img.shields.io/codeclimate/coverage/renfordt/larvatar?logo=codeclimate)](https://codeclimate.com/github/renfordt/larvatar/test_coverage)\r\n[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/renfordt/larvatar?logo=codeclimate)](https://codeclimate.com/github/renfordt/larvatar/maintainability)\r\n\r\nLarvatar is a package that combines different avatar styles, like Gravatar, Initials Avatar.\r\n\r\n![Avatar Types](avatars.png)\r\n\r\n## Installation\r\n\r\nThe recommended way of installing Larvatar is to use [Composer](https://getcomposer.org/). Run the following command to\r\ninstall it to you project:\r\n\r\n```\r\ncomposer require renfordt/larvatar\r\n```\r\n\r\n## Upgrading to 2.0\r\n\r\nVersion 2.0 brings many breaking changes. Check the [Upgrade Guide](UPGRADING.md) to avoid any issues.\r\n\r\n## Basic Usage\r\n\r\nInclude the LarvatarTrait with `use Renfordt\\Larvatar\\Traits\\LarvatarTrait;` in your user class and add the following method:\r\n\r\n```php\r\n    /**\r\n     * Generate and retrieve the avatar URL or HTML for the user.\r\n     *\r\n     * @param int $size The size of the avatar in pixels.\r\n     * @param bool $encoding Whether to return the encoded image as HTML.\r\n     * @return string The avatar as a string URL or encoded HTML.\r\n     */\r\n    public function getAvatar(int $size = 100, bool $encoding = true): string\r\n    {\r\n        $larvatar = $this-\u003egetLarvatar($this-\u003ename, $this-\u003eemail);\r\n        $larvatar-\u003esetSize($size);\r\n        $larvatar-\u003esetWeight('600');\r\n        return $larvatar-\u003egetImageHTML(true);\r\n    }\r\n```\r\n\r\nAdjust the method as you please, only requirement is that the methods name is `getAvatar()`.\r\n\r\n## Advanced Usage\r\n\r\nThe general usage is simple. Create a new Larvatar class, insert name and email and the avatar type you wish.\r\n\r\n```php\r\n\u003c?php\r\nuse Renfordt\\Larvatar\\Enum\\LarvatarTypes;\r\nuse Renfordt\\Larvatar\\Larvatar;\r\n\r\n// Larvatar::make($type, $name = '', $email = '')\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: 'Test Name'\r\n        );\r\n\r\n// Optional settings    \r\n$larvatar-\u003esetFont('Roboto,sans-serif', './font/Roboto-bold.ttf');\r\n$larvatar-\u003esetSize(100);\r\n\r\n// Get the SVG Code for embedding directly in your page\r\necho $larvatar-\u003egetImageHTML();\r\n\r\n// if you need base64 encryption, currently this works only for InitialsAvatar\r\necho $larvatar-\u003egetImageHTML('base64');\r\n// or if you need just the base64 string:\r\necho $larvatar-\u003egetBase64();\r\n```\r\n\r\nAlternatively you can create an instance of the `Name` class, which provides you more possibilities.\r\n\r\n```php\r\n$name = \\Renfordt\\Larvatar\\Name::make('Test Name');\r\n\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: $name\r\n        );\r\n```\r\n\r\nThere are currently nine different types of avatars available:\r\n\r\n```php\r\n// 1) Microsoft Teams like avatar with initials\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::InitialsAvatar;\r\n// 2) Identicons with more possibilities to adjust\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::IdenticonLarvatar;\r\n\r\n// 3) Gravatar\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::Gravatar;\r\n// 4) (Gravatar) MysticPerson, simple cartoon-style silhouette (default)\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::mp;\r\n// 5) (Gravatar) A geometric pattern based on an email hash\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::identicon;\r\n// 6) (Gravatar) A generated monster different colors and faces \r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::monsterid;\r\n// 7) (Gravatar) generated faces with differing features and backgrounds\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::wavatar;\r\n// 8) (Gravatar) 8-bit arcade-style pixelated faces\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::retro;\r\n// 9) (Gravatar) A generated robot with different colors, faces, etc\r\n\\Renfordt\\Larvatar\\Enum\\LarvatarTypes::robohash;\r\n```\r\n\r\n## InitialsAvatar\r\n\r\n### Forms\r\n\r\nThe InitialsAvatar gives you the possibility to choose between three different forms. A circle, which is the default, a\r\nhexagon and a square. Choose it by using the `setForm()` method. The input is either a string or a value of the\r\nEnum `FormTypes`.\r\n\r\n```PHP\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: 'Test Name'\r\n        );\r\n$larvatar-\u003einitialsAvatar-\u003esetForm('circle');\r\n$larvatar-\u003einitialsAvatar-\u003esetForm('square');\r\n$larvatar-\u003einitialsAvatar-\u003esetForm('hexagon');\r\n\r\n$larvatar-\u003einitialsAvatar-\u003esetForm(FormTypes::Circle);\r\n$larvatar-\u003einitialsAvatar-\u003esetForm(FormTypes::Square);\r\n$larvatar-\u003einitialsAvatar-\u003esetForm(FormTypes::Hexagon);\r\n```\r\n\r\nIf you are using the hexagon form, you have additionally the possibility to rotate the form:\r\n\r\n```PHP\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: 'Test Name'\r\n        );\r\n$larvatar-\u003einitialsAvatar-\u003esetForm(FormTypes::Hexagon);\r\n$larvatar-\u003einitialsAvatar-\u003esetRotation(30);\r\n```\r\n\r\n### Colors\r\n\r\nUsually the colors will be automatically selected by the provided name.\r\nIf you for some case want to manually set the contrast of the colors, you can use the methods `setBackgroundLightness()`\r\nand `setTextLightness()`. The parameter is a float with a value range `0` to `1` where `0` means a darker color and `1`\r\nis a lighter color.\r\n\r\n```PHP\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: 'Test Name'\r\n        );\r\n$larvatar-\u003einitialsAvatar-\u003esetBackgroundLightness(0.1);\r\n$larvatar-\u003einitialsAvatar-\u003esetTextLightness(0.8);\r\n```\r\n\r\nAdditionally, you can change the offset which will generate a different color.\r\n\r\n```PHP\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: 'Test Name'\r\n        );\r\n$larvatar-\u003einitialsAvatar-\u003esetOffset(4);\r\n```\r\n\r\n### Font Weight\r\n\r\nYou can also change the font weight with the method `setFontWeight()`.\r\n\r\n```PHP\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::InitialsAvatar,\r\n        name: 'Test Name'\r\n        );\r\n$larvatar-\u003einitialsAvatar-\u003esetFontWeight('bold');\r\n```\r\n\r\n## Identicons (Larvatar Style)\r\n\r\n```PHP\r\n$larvatar = Larvatar::make(\r\n        type: LarvatarTypes::IdenticonLarvatar,\r\n        name: 'Test Name'\r\n        );\r\n        \r\n// optional settings\r\n$larvatar-\u003eidenticon-\u003esetSymmetry(false);\r\n$larvatar-\u003eidenticon-\u003esetPixels(8);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenfordt%2Flarvatar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenfordt%2Flarvatar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenfordt%2Flarvatar/lists"}