Integrate with non-Laravel PHP projects
masterlaravolt/avatar in a standard PHP project, include the Composer autoloader, import the Avatar class, and instantiate it with a configuration array.repository·master·Indexed 24 days ago
https://github.com/laravolt/avatarA PHP package for generating unique user avatars based on initials. It supports multiple output formats including Base64, SVG, files, and Gravatar URLs. The library provides a Laravel facade, Lumen service provider, and integration options for standard PHP projects. Advanced features include HD avatar generation, responsive sizes, batch exporting, sprite sheet creation, and storage optimization with automated cleanup.
laravolt/avatar in a standard PHP project, include the Composer autoloader, import the Avatar class, and instantiate it with a configuration array.If you are using Lumen, you must manually register the service provider in your application bootstrap file:
$app->register(Laravolt\Avatar\LumenServiceProvider);Install the package via Composer. In Laravel, the service provider and Avatar facade are automatically registered via auto-discovery.
composer require laravolt/avatarTo customize the avatar generation settings, publish the configuration file to config/laravolt/avatar.php using the following Artisan command:
php artisan vendor:publish --provider="Laravolt\Avatar\ServiceProvider"'ascii' => true in config/avatar.php.The package provides two configuration files that can be published to your application's config directory for customization. Use the standard Laravel vendor:publish command with the config tag.
Available configuration files:
laravolt.avatar: Main configuration.laravolt.avatar.hd: High-definition (HD) configuration.To use Laravolt Avatar in a Lumen application, register the Laravolt\Avatar\LumenServiceProvider in your bootstrap/app.php file. This provider binds the avatar and avatar.generator services to the application container.
Once registered, you can resolve the avatar service from the container using the avatar key.
toBase64() to output a data-uri (base64 image data). This is useful for embedding images directly in HTML <img> tags.toGravatar() to generate a URL for a Gravatar image based on an email address. You can pass an array of parameters (like d, r, s) to customize the Gravatar output.If you need to perform advanced image manipulation, use getImageObject() to retrieve the underlying Intervention Image instance.
Avatar::create('Abdul Somad')->getImageObject();toSvg() to output the avatar as an SVG. You can customize the font family using setFontFamily() and make the SVG responsive using setResponsive() (which excludes height and width attributes).You can chain methods on the Avatar::create() call to override default configuration settings for a specific instance.
Avatar::create('Soekarno')->setDimension(100); // width = height = 100
Avatar::create('Soekarno')->setDimension(100, 200); // width = 100, height = 200
Avatar::create('Soekarno')->setBackground('#001122');
Avatar::create('Soekarno')->setForeground('#999999');
Avatar::create('Soekarno')->setFontSize(72);
Avatar::create('Soekarno')->setFont('/path/to/font.ttf');
Avatar::create('Soekarno')->setBorder(1, '#aabbcc');
Avatar::create('Soekarno')->setBorder(1, '#aabbcc', 10); // radius (only for SVG)
Avatar::create('Soekarno')->setShape('square');
Avatar::create('Soekarno')->setTheme('colorful');
Avatar::create('Soekarno')->setTheme(['grayscale-light', 'grayscale-dark']);
// Chaining example
Avatar::create('Habibie')->setDimension(50)->setFontSize(18)->toBase64();