{"id":13452965,"url":"https://github.com/laravolt/avatar","last_synced_at":"2025-05-11T05:46:05.402Z","repository":{"id":41483193,"uuid":"44089758","full_name":"laravolt/avatar","owner":"laravolt","description":"Plug n play avatar, turn name, email, and any other string into beautiful avatar (or gravatar), effortless. ","archived":false,"fork":false,"pushed_at":"2025-04-17T01:13:13.000Z","size":511,"stargazers_count":1949,"open_issues_count":0,"forks_count":184,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-05-11T05:45:59.155Z","etag":null,"topics":["avatar","gravatar","laravel-package","php","php-library"],"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/laravolt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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,"zenodo":null},"funding":{"patreon":"uyab","ko_fi":"bayuhendra","custom":["https://paypal.me/bayuhendra"]}},"created_at":"2015-10-12T07:01:40.000Z","updated_at":"2025-04-30T03:45:32.000Z","dependencies_parsed_at":"2024-01-06T14:12:29.926Z","dependency_job_id":"233220d7-2abe-4845-a709-6aaa3f1a3c78","html_url":"https://github.com/laravolt/avatar","commit_stats":{"total_commits":211,"total_committers":21,"mean_commits":"10.047619047619047","dds":"0.36492890995260663","last_synced_commit":"a4d533521191449fdb5efc8d9ed015bd639c2307"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravolt%2Favatar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravolt%2Favatar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravolt%2Favatar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravolt%2Favatar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laravolt","download_url":"https://codeload.github.com/laravolt/avatar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523720,"owners_count":21921818,"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","laravel-package","php","php-library"],"created_at":"2024-07-31T08:00:29.482Z","updated_at":"2025-05-11T05:46:05.382Z","avatar_url":"https://github.com/laravolt.png","language":"PHP","readme":"# laravolt/avatar\n\n[![Total Downloads](https://img.shields.io/packagist/dt/laravolt/avatar.svg?style=flat)](https://packagist.org/packages/laravolt/avatar)\n[![Monthly Downloads](https://img.shields.io/packagist/dm/laravolt/avatar.svg?style=flat)](https://packagist.org/packages/laravolt/avatar)\n[![Daily Downloads](https://img.shields.io/packagist/dd/laravolt/avatar.svg?style=flat)](https://packagist.org/packages/laravolt/avatar)\n[![Run Tests](https://github.com/laravolt/avatar/workflows/run-tests/badge.svg)](https://github.com/laravolt/avatar/workflows/run-tests/badge.svg)\n\n![Preview](https://user-images.githubusercontent.com/149716/29503524-840ccd0c-8662-11e7-92f9-9ec3ed8a24af.png)\n\nDisplay unique avatar for any user based on their (initials) name.\n\n## Preview\n![Preview](https://cloud.githubusercontent.com/assets/149716/26735022/6dbd77e2-47ea-11e7-8a05-7772465309c5.png)\n## :film_strip: Video Tutorial \n[\u003cimg src=\"https://img.youtube.com/vi/jD0wu88c5kw/0.jpg\" width=\"250\"\u003e](https://youtu.be/jD0wu88c5kw)\n\n## Installation\nThis package originally built for Laravel, but can also be used in any PHP project.\n\n[Read more about integration with PHP project here.](#integration-with-other-php-project)\n\n### Laravel \u003e= 5.2:\n```bash\ncomposer require laravolt/avatar\n```\n\n### Laravel 5.1:\n```bash\ncomposer require laravolt/avatar ~0.3\n```\n\n## Service Provider \u0026 Facade\n**Note: only for Laravel 5.4 and below, because since Laravel 5.5 we use package auto-discovery.**\n\n```php\nLaravolt\\Avatar\\ServiceProvider::class,\n\n...\n\n'Avatar'    =\u003e Laravolt\\Avatar\\Facade::class,\n```\n\n## Publish Config (optional)\n```php\nphp artisan vendor:publish --provider=\"Laravolt\\Avatar\\ServiceProvider\"\n```\nThis will create config file located in `config/laravolt/avatar.php`.\n\n## Lumen Service Provider\n\n```php\n$app-\u003eregister(Laravolt\\Avatar\\LumenServiceProvider);\n```\n\n## Usage\n\n### Output as base64\n```php\n//this will output data-uri (base64 image data)\n//something like data:image/png;base64,iVBORw0KGg....\nAvatar::create('Joko Widodo')-\u003etoBase64();\n\n//use in view\n//this will display initials JW as an image\n\u003cimg src=\"{{ Avatar::create('Joko Widodo')-\u003etoBase64() }}\" /\u003e\n```\n\n### Save as file\n```php\nAvatar::create('Susilo Bambang Yudhoyono')-\u003esave('sample.png');\nAvatar::create('Susilo Bambang Yudhoyono')-\u003esave('sample.jpg', 100); // quality = 100\n```\n\n### Output as Gravatar\n```php\nAvatar::create('uyab@example.net')-\u003etoGravatar();\n// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee\n\nAvatar::create('uyab@example.net')-\u003etoGravatar(['d' =\u003e 'identicon', 'r' =\u003e 'pg', 's' =\u003e 100]);\n// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee?d=identicon\u0026r=pg\u0026s=100\n```\nGravatar parameter reference: https://docs.gravatar.com/api/avatars/images/\n\n### Output as SVG\n```php\nAvatar::create('Susilo Bambang Yudhoyono')-\u003etoSvg();\n```\n\nYou may specify custom font-family for your SVG text.\n```html\n\u003chead\u003e\n    \u003c!--Prepare custom font family, using Google Fonts--\u003e\n    \u003clink href=\"https://fonts.googleapis.com/css?family=Laravolt\" rel=\"stylesheet\"\u003e\n\n    \u003c!--OR--\u003e\n\n    \u003c!--Setup your own style--\u003e\n    \u003cstyle\u003e\n    @font-face {\n        font-family: Laravolt;\n        src: url({{ asset('fonts/laravolt.woff')) }});\n    }\n    \u003c/style\u003e\n\u003c/head\u003e\n```\n\n```php\nAvatar::create('Susilo Bambang Yudhoyono')-\u003esetFontFamily('Laravolt')-\u003etoSvg();\n```\n\nYou may make the SVG responsive. This excludes the height and width attributes.\n```php\nAvatar::create('Susilo Bambang Yudhoyono')-\u003esetResponsive()-\u003etoSvg();\n```\n\n## Get underlying Intervention image object\n```php\nAvatar::create('Abdul Somad')-\u003egetImageObject();\n```\nThe method will return an instance of [Intervention image object](http://image.intervention.io/), so you can use it for further purposes.\n\n## Non-ASCII Character\nBy default, this package will try to output any initials letter as it is. If the name supplied contains any non-ASCII character (e.g. ā, Ě, ǽ) then the result will depend on which font used (see config). It the font supports characters supplied, it will successfully displayed, otherwise it will not.\n\nAlternatively, we can convert all non-ascii to their closest ASCII counterparts. If no closest coutnerparts found, those characters are removed. Thanks to [Stringy](https://github.com/danielstjules/Stringy) for providing such useful functions. What we need is just change one line in `config/avatar.php`:\n\n```php\n    'ascii'    =\u003e true,\n```\n\n## Configuration\n```php\n\u003c?php\n/*\n * Set specific configuration variables here\n */\nreturn [\n\n    /*\n    |--------------------------------------------------------------------------\n    | Image Driver\n    |--------------------------------------------------------------------------\n    | Avatar use Intervention Image library to process image.\n    | Meanwhile, Intervention Image supports \"GD Library\" and \"Imagick\" to process images\n    | internally. You may choose one of them according to your PHP\n    | configuration. By default PHP's \"Imagick\" implementation is used.\n    |\n    | Supported: \"gd\", \"imagick\"\n    |\n    */\n    'driver'    =\u003e 'gd',\n\n    // Initial generator class\n    'generator' =\u003e \\Laravolt\\Avatar\\Generator\\DefaultGenerator::class,\n\n    // Whether all characters supplied must be replaced with their closest ASCII counterparts\n    'ascii'    =\u003e false,\n\n    // Image shape: circle or square\n    'shape' =\u003e 'circle',\n\n    // Image width, in pixel\n    'width'    =\u003e 100,\n\n    // Image height, in pixel\n    'height'   =\u003e 100,\n\n    // Number of characters used as initials. If name consists of single word, the first N character will be used\n    'chars'    =\u003e 2,\n\n    // font size\n    'fontSize' =\u003e 48,\n\n    // convert initial letter in uppercase\n    'uppercase' =\u003e false,\n\n    // Right to Left (RTL)\n    'rtl' =\u003e false,\n\n    // Fonts used to render text.\n    // If contains more than one fonts, randomly selected based on name supplied\n    'fonts'    =\u003e [__DIR__.'/../fonts/OpenSans-Bold.ttf', __DIR__.'/../fonts/rockwell.ttf'],\n\n    // List of foreground colors to be used, randomly selected based on name supplied\n    'foregrounds'   =\u003e [\n        '#FFFFFF',\n    ],\n\n    // List of background colors to be used, randomly selected based on name supplied\n    'backgrounds'   =\u003e [\n        '#f44336',\n        '#E91E63',\n        '#9C27B0',\n        '#673AB7',\n        '#3F51B5',\n        '#2196F3',\n        '#03A9F4',\n        '#00BCD4',\n        '#009688',\n        '#4CAF50',\n        '#8BC34A',\n        '#CDDC39',\n        '#FFC107',\n        '#FF9800',\n        '#FF5722',\n    ],\n\n    'border'    =\u003e [\n        'size'  =\u003e 1,\n\n        // border color, available value are:\n        // 'foreground' (same as foreground color)\n        // 'background' (same as background color)\n        // or any valid hex ('#aabbcc')\n        'color' =\u003e 'background',\n\n        // border radius, only works for SVG\n        'radius' =\u003e 0,\n    ],\n\n    // List of theme name to be used when rendering avatar\n    // Possible values are:\n    // 1. Theme name as string: 'colorful'\n    // 2. Or array of string name: ['grayscale-light', 'grayscale-dark']\n    // 3. Or wildcard \"*\" to use all defined themes\n    'theme' =\u003e ['*'],\n\n    // Predefined themes\n    // Available theme attributes are:\n    // shape, chars, backgrounds, foregrounds, fonts, fontSize, width, height, ascii, uppercase, and border.\n    'themes' =\u003e [\n        'grayscale-light' =\u003e [\n            'backgrounds' =\u003e ['#edf2f7', '#e2e8f0', '#cbd5e0'],\n            'foregrounds' =\u003e ['#a0aec0'],\n        ],\n        'grayscale-dark' =\u003e [\n            'backgrounds' =\u003e ['#2d3748', '#4a5568', '#718096'],\n            'foregrounds' =\u003e ['#e2e8f0'],\n        ],\n        'colorful' =\u003e [\n            'backgrounds' =\u003e [\n                '#f44336',\n                '#E91E63',\n                '#9C27B0',\n                '#673AB7',\n                '#3F51B5',\n                '#2196F3',\n                '#03A9F4',\n                '#00BCD4',\n                '#009688',\n                '#4CAF50',\n                '#8BC34A',\n                '#CDDC39',\n                '#FFC107',\n                '#FF9800',\n                '#FF5722',\n            ],\n            'foregrounds' =\u003e ['#FFFFFF'],\n        ],\n    ]\n];\n```\n\n## Overriding config at runtime\nWe can overriding configuration at runtime by using following functions:\n\n```php\nAvatar::create('Soekarno')-\u003esetDimension(100);//width = height = 100 pixel\nAvatar::create('Soekarno')-\u003esetDimension(100, 200); // width = 100, height = 200\nAvatar::create('Soekarno')-\u003esetBackground('#001122');\nAvatar::create('Soekarno')-\u003esetForeground('#999999');\nAvatar::create('Soekarno')-\u003esetFontSize(72);\nAvatar::create('Soekarno')-\u003esetFont('/path/to/font.ttf');\nAvatar::create('Soekarno')-\u003esetBorder(1, '#aabbcc'); // size = 1, color = #aabbcc\nAvatar::create('Soekarno')-\u003esetBorder(1, '#aabbcc', 10); // size = 1, color = #aabbcc, border radius = 10 (only for SVG)\nAvatar::create('Soekarno')-\u003esetShape('square');\n\n// Available since 3.0.0\nAvatar::create('Soekarno')-\u003esetTheme('colorful'); // set exact theme\nAvatar::create('Soekarno')-\u003esetTheme(['grayscale-light', 'grayscale-dark']); // theme will be randomized from these two options\n\n// chaining\nAvatar::create('Habibie')-\u003esetDimension(50)-\u003esetFontSize(18)-\u003etoBase64();\n```\n\n## Integration with other PHP project\n```php\n// include composer autoload\nrequire 'vendor/autoload.php';\n\n// import the Avatar class\nuse Laravolt\\Avatar\\Avatar;\n\n// create your first avatar\n$avatar = new Avatar($config);\n$avatar-\u003ecreate('John Doe')-\u003etoBase64();\n$avatar-\u003ecreate('John Doe')-\u003esave('path/to/file.png', $quality = 90);\n```\n`$config` is just an ordinary array with same format as explained above (See [Configuration](#configuration)).\n\n## Support Us\n\n### Buy Me A Coffee\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png)](https://www.buymeacoffee.com/uyab)\n\n### Donate Via PayPal\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/bayuhendra)\n\n### Traktir Saya\n\u003ca href=\"https://trakteer.id/bayuhendra/tip\" target=\"_blank\"\u003e\u003cimg id=\"wse-buttons-preview\" src=\"https://cdn.trakteer.id/images/embed/trbtn-red-5.png\" height=\"40\" style=\"border:0px;height:40px;\" alt=\"Trakteer Saya\"\u003e\u003c/a\u003e\n","funding_links":["https://patreon.com/uyab","https://ko-fi.com/bayuhendra","https://paypal.me/bayuhendra","https://www.buymeacoffee.com/uyab"],"categories":["Popular Packages","Laravel","PHP","php","Paquetes utiles","A"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravolt%2Favatar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaravolt%2Favatar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravolt%2Favatar/lists"}