{"id":15025119,"url":"https://github.com/lasserafn/php-initial-avatar-generator","last_synced_at":"2025-05-14T07:10:04.405Z","repository":{"id":52452801,"uuid":"78973710","full_name":"LasseRafn/php-initial-avatar-generator","owner":"LasseRafn","description":"Generate avatars with initials from user names.","archived":false,"fork":false,"pushed_at":"2025-02-27T10:44:05.000Z","size":42823,"stargazers_count":429,"open_issues_count":7,"forks_count":67,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-11T02:51:39.684Z","etag":null,"topics":["avatar","avatar-generator","generator","image","intervention","php","php7","php8","profile-picture"],"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/LasseRafn.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":{"open_collective":"ui-avatars"}},"created_at":"2017-01-14T23:23:47.000Z","updated_at":"2025-04-10T09:37:23.000Z","dependencies_parsed_at":"2025-04-11T02:51:30.349Z","dependency_job_id":null,"html_url":"https://github.com/LasseRafn/php-initial-avatar-generator","commit_stats":{"total_commits":185,"total_committers":11,"mean_commits":"16.818181818181817","dds":"0.10810810810810811","last_synced_commit":"ffe43d8df3f18646d7b23011272cce2d71400e1f"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseRafn%2Fphp-initial-avatar-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseRafn%2Fphp-initial-avatar-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseRafn%2Fphp-initial-avatar-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseRafn%2Fphp-initial-avatar-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LasseRafn","download_url":"https://codeload.github.com/LasseRafn/php-initial-avatar-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092790,"owners_count":22013290,"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","avatar-generator","generator","image","intervention","php","php7","php8","profile-picture"],"created_at":"2024-09-24T20:01:32.493Z","updated_at":"2025-05-14T07:09:59.392Z","avatar_url":"https://github.com/LasseRafn.png","language":"PHP","readme":"# Generate avatars with initials\nEver seen those avatars (basically everywhere) that has your initials — mine would be LR; Lasse Rafn — well this package allows you to generate those, in a simple manner.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://ui-avatars.com/assets/promo-new.png\" alt=\"Banner\" /\u003e\n\u003c/p\u003e\n\n \n\u003cp align=\"center\"\u003e \n\u003ca href=\"https://github.com/LasseRafn/php-initial-avatar-generator/actions/workflows/test.yml\"\u003e\u003cimg src=\"https://github.com/LasseRafn/php-initial-avatar-generator/actions/workflows/test.yml/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://otterwise.app/github/lasserafn/php-initial-avatar-generator\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://otterwise.app/badge/github/lasserafn/php-initial-avatar-generator/coverage/6db6fcbb-95a6-446a-b5a1-15d7b1809dca\" alt=\"OtterWise Coverage\"\u003e\u003c/a\u003e\n\u003ca href=\"https://otterwise.app/github/lasserafn/php-initial-avatar-generator\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://otterwise.app/badge/github/lasserafn/php-initial-avatar-generator/complexity/6db6fcbb-95a6-446a-b5a1-15d7b1809dca\" alt=\"OtterWise Coverage\"\u003e\u003c/a\u003e\n\u003ca href=\"https://styleci.io/repos/78973710\"\u003e\u003cimg src=\"https://styleci.io/repos/78973710/shield?branch=master\" alt=\"StyleCI Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/LasseRafn/php-initial-avatar-generator\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/LasseRafn/php-initial-avatar-generator.svg?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/LasseRafn/php-initial-avatar-generator\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/LasseRafn/php-initial-avatar-generator.svg?style=flat-square\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/LasseRafn/php-initial-avatar-generator\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/LasseRafn/php-initial-avatar-generator.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n \u003ca href=\"https://getotterwise.com?ref=ui-avatars-gh\" target=\"_blank\" align=\"center\"\u003e\u003cimg style=\"width: 600px;\" src=\"https://getotterwise.com/images/ext/uiavatars-ad.png\" alt=\"OtterWise Code Coverage reporting\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/ui-avatars#backer)]\n\n\u003ca href=\"https://opencollective.com/ui-avatars#backers\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/backers.svg?width=890\"\u003e\u003c/a\u003e\n\n## Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/ui-avatars#sponsor)]\n\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/0/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/0/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/1/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/1/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/2/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/2/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/3/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/3/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/4/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/4/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/5/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/5/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/6/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/6/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/7/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/7/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/8/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/8/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/ui-avatars/sponsor/9/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/ui-avatars/sponsor/9/avatar.svg\"\u003e\u003c/a\u003e\n\n**There's also a api you can use: [https://ui-avatars.com](https://ui-avatars.com)**\n\n## Installation\nYou just require using composer and you're good to go!\n````bash\ncomposer require lasserafn/php-initial-avatar-generator\n````\nRad, *and long*, package name.. huh? Sorry. I'm not very good with names.\n\n## Usage\nAs with installation, usage is quite simple. Generating a image is done by running:\n````php\n$avatar = new LasseRafn\\InitialAvatarGenerator\\InitialAvatar();\n\n$image = $avatar-\u003ename('Lasse Rafn')-\u003egenerate();\n````\n\nThats it! The method will return a instance of [Image from Intervention](https://github.com/Intervention/image) so you can stream, download or even encode the image:\n````php\nreturn $image-\u003estream('png', 100);\n````\nYou can also just pass along the initials, and it will use those. Should you just include a first name, it will use the first two letters of it.\n\n\n### Example usage in a webpage\nTo display the image generated by the InitialAvatarGenerator library directly on a webpage, you can utilize PHP headers to output the image as a stream or generate a temporary file and display it using an ```\u003cimg\u003e``` tag.\n\nTo output the image as a stream, you can create a separate PHP endpoint (like avatar.php) that generates the avatar image and streams it as a PNG. Then, you use the URL of this endpoint as the src of an ```\u003cimg\u003e``` tag on your webpage.\n\nAn example endpoint file (**avatar.php**) is below:\n\n```php\n\u003c?php\nrequire 'vendor/autoload.php'; \n\nuse LasseRafn\\InitialAvatarGenerator\\InitialAvatar;\n\nheader('Content-Type: image/png'); // Set the content type to PNG\n\n$avatar = new InitialAvatar();\n$name = isset($_GET['name']) ? $_GET['name'] : 'Default User';\n\n// Generate the image\n$image = $avatar-\u003ename($name)-\u003egenerate();\n\n// Stream the image directly to the output\necho $image-\u003estream('png', 100);\nexit;\n\n```\n\nIn the HTML file, you can reference the snippet below:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003ctitle\u003eAvatar Example\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eUser Avatar\u003c/h1\u003e\n    \u003c!-- Use the PHP endpoint as the image source --\u003e\n    \u003cimg src=\"avatar.php?name=John Doe\" alt=\"Avatar for John Doe\" width=\"100\" height=\"100\"\u003e\n\n    \u003cimg src=\"avatar.php?name=Jane Smith\" alt=\"Avatar for Jane Smith\" width=\"100\" height=\"100\"\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\n```\n\n## SVG generation\n````php\n$avatar = new LasseRafn\\InitialAvatarGenerator\\InitialAvatar();\n\necho $avatar-\u003ename('Lasse Rafn')-\u003egenerateSvg()-\u003etoXMLString(); // returns SVG XML string\n````\n\n## Supported methods and parameters\nOf cause, passing a name is not the only thing this sweet thing does!\n\n### Name (initials) - default: JD\n````php\n$image = $avatar-\u003ename('Albert Magnum')-\u003egenerate();\n````\n\n### AutoFont - default: false\n\nWill detect language script (using [lasserafn/php-string-script-language](https://github.com/lasserafn/php-string-script-language)) and use a font that supports it.\n\n````php\n$image = $avatar-\u003eautoFont()-\u003egenerate();\n````\n\n### Width - default: 48\n````php\n// will be 96 pixels wide.\n$image = $avatar-\u003ewidth(96)-\u003egenerate();\n````\n\n### Height - default: 48\n````php\n// will be 96 pixels tall.\n$image = $avatar-\u003eheight(96)-\u003egenerate();\n````\n\n### Size - default: 48 (proxy for `$avatar-\u003ewidth(X)-\u003eheight(X)`)\n````php\n// will be 96x96 pixels.\n$image = $avatar-\u003esize(96)-\u003egenerate();\n````\n\n### Background color - default: #f0e9e9\n````php\n// will be red\n$image = $avatar-\u003ebackground('#ff0000')-\u003egenerate();\n````\n\n### Font color - default: #8b5d5d\n````php\n// will be red\n$image = $avatar-\u003ecolor('#ff0000')-\u003egenerate();\n````\n\n### Auto Color\n````php\n// Will choose a background color based on `name` and a contrasting font color. The color for a specific name will always be the same.\n$image = $avatar-\u003eautoColor()-\u003egenerate();\n````\n\n### Font file - default: /fonts/OpenSans-Regular.ttf\nTwo fonts with two variants are included:\n* /fonts/OpenSans-Regular.ttf\n* /fonts/OpenSans-Semibold.ttf\n* /fonts/NotoSans-Bold.ttf\n* /fonts/NotoSans-Regular.ttf\n\nThe method will look for the font, if none found it will append `__DIR__` and try again, and if not it will default to the first GD Internal Font.\nIf you input an integer between 1 and 5, it will use a GD Internal font as per that number.\n\n````php\n// will be Semibold\n$image = $avatar-\u003efont('/fonts/OpenSans-Semibold.ttf')-\u003egenerate();\n````\n\n### Font name (for SVGs) - default: Open Sans, sans-serif\n\n````php\n$image = $avatar-\u003efontName('Arial, Helvetica, sans-serif')-\u003egenerate();\n````\n\n### Length - default: 2\n````php\n$image = $avatar-\u003ename('John Doe Johnson')-\u003elength(3)-\u003egenerate(); // 3 letters = JDJ\n````\n\n### Switching driver - default: gd\n````php\n$image = $avatar-\u003egd()-\u003egenerate(); // Uses GD driver\n$image = $avatar-\u003eimagick()-\u003egenerate(); // Uses Imagick driver\n````\n\n### Rounded - default: false\n````php\n$image = $avatar-\u003erounded()-\u003egenerate();\n````\n\n### Smooth - default: false\n\nMakes rounding smoother with a resizing hack. Could be slower.\n\n````php\n$image = $avatar-\u003erounded()-\u003esmooth()-\u003egenerate();\n````\n\nIf you are going to use `rounded()`, you want to use `smooth()` to avoid pixelated edges. Disabled by default because it _COULD_ be slower.\nI would recommend just rounding with CSS.\n\n### Font Size - default: 0.5\n````php\n$image = $avatar-\u003efontSize(0.25)-\u003egenerate(); // Font will be 25% of image size.\n````\nIf the Image size is 50px and fontSize is 0.5, the font size will be 25px.\n\n## Chaining it all together\nWe will not use the -\u003efont() method in this example; as I like the regular one.\n\n````php\nreturn $avatar-\u003ename('Lasse Rafn')\n              -\u003elength(2)\n              -\u003efontSize(0.5)\n              -\u003esize(96) // 48 * 2\n              -\u003ebackground('#8BC34A')\n              -\u003ecolor('#fff')\n              -\u003egenerate()\n              -\u003estream('png', 100);\n````\n\nNow, using that in a image (sized 48x48 pixels for retina):\n````html\n\u003cimg src=\"url-for-avatar-generation\" width=\"48\" height=\"48\" style=\"border-radius: 100%\" /\u003e\n````\nWill yield:\n\n\u003cimg src=\"https://raw.githubusercontent.com/LasseRafn/php-initial-avatar-generator/master/demo_result.png\" width=\"48\" height=\"48\" alt=\"Result\" style=\"border-radius: 100%\" /\u003e\n\n*Rounded for appearance; the actual avatar is a filled square*\n\n## Font Awesome Support\n\nThe package supports FontAwesome (v5) and already distributes the free version as `otf` format (see `/fonts` folder).\n\nHowever, when using FontAwesome you may want to display one specific icon instead of the user's initials. This package, therefore, provides a handy `glyph($code)` method to be used along with FontAwesome.\n\nFirst, you need to \"find\" the respective unicode for the glyph you want to insert. For example, you may want to display a typical \"user\" icon (unicode: `f007`). The unicode is located near the name of the icon (e.g., see here the user icon as an example here: [https://fontawesome.com/icons/user](https://fontawesome.com/icons/user) ).\n\nAn example for rendering a red avatar with a white \"user\" glyph would look like this:\n\n```php\n// note that we\n// 1) use glyph() instead of name\n// 2) change the font to FontAwesome!\nreturn $avatar-\u003eglyph('f007')\n              -\u003efont('/fonts/FontAwesome5Free-Regular-400.otf')\n              -\u003ecolor('#fff')\n              -\u003ebackground('#ff0000')\n              -\u003egenerate()\n              -\u003estream('png', 100);\n```\n\n## Requirements\n* PHP +7.0\n* Fileinfo Extension (from intervention/image)\n\n## Script/Language support\nSome letters are not supported by the default font files, so I added some fonts to add support. You must use `autoFont()` to enable this feature. Supported are:\n\n* Arabic\n* Armenian\n* Bengali\n* Georgian\n* Hebrew\n* Mongolian\n* Chinese\n* Thai\n* Tibetan\n\n## [Contributors](https://github.com/LasseRafn/php-initial-avatar-generator/graphs/contributors)\nOpen Source is best when supported by a community. Any size of contribution is **very** appreciated.\n\n## Supported Image Libraries (from intervention/image)\n* GD Library (\u003e=2.0)\n* Imagick PHP extension (\u003e=6.5.7)\n","funding_links":["https://opencollective.com/ui-avatars"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flasserafn%2Fphp-initial-avatar-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flasserafn%2Fphp-initial-avatar-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flasserafn%2Fphp-initial-avatar-generator/lists"}