All Projects → laravolt → Avatar

laravolt / Avatar

Licence: mit
Plug n play avatar, turn name, email, and any other string into beautiful avatar (or gravatar), effortless.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Avatar

Gravatar
👤 Gravatar Helper & Generator (Laravel supported)
Stars: ✭ 19 (-98.75%)
Mutual labels:  avatar, gravatar
interfaces
A diverse set of royalty-free user avatars to be used for marketing graphics and application screenshots.
Stars: ✭ 50 (-96.72%)
Mutual labels:  avatar, profile-picture
avatars-io
👤 Wanna get a social media avatar? Avatars-io makes it easy for you. Just give a username then get an avatar!
Stars: ✭ 13 (-99.15%)
Mutual labels:  avatar, gravatar
boring-avatars
Boring avatars is a tiny JavaScript React library that generates custom, SVG-based avatars from any username and color palette.
Stars: ✭ 3,582 (+134.89%)
Mutual labels:  avatar, profile-picture
mk-letter-avatar
🅰 WordPress 字母头像插件(纯前端实现版) WordPress letter avatar plugin
Stars: ✭ 42 (-97.25%)
Mutual labels:  avatar, gravatar
Laravel Tracer
Shows the path of each blade file loaded in a template
Stars: ✭ 96 (-93.7%)
Mutual labels:  laravel-package
Laravel Bank Statements
Laravel package to collect your bank statements history. Currently support for parsing statements history from BCA, Mandiri, BNI, and MUAMALAT e-banking websites.
Stars: ✭ 105 (-93.11%)
Mutual labels:  laravel-package
Icotar
A free colorful icon avatar generator.
Stars: ✭ 94 (-93.84%)
Mutual labels:  avatar
Laravel Favicon Extractor
Extract a favicon from any website and save it to your local storage
Stars: ✭ 92 (-93.97%)
Mutual labels:  laravel-package
Laravel Fpdf
Create PDFs with Laravel, provides FPDF version 1.82
Stars: ✭ 108 (-92.92%)
Mutual labels:  laravel-package
Cray
A Laravel package to help you generate nearly complete CRUD pages like crazy!
Stars: ✭ 108 (-92.92%)
Mutual labels:  laravel-package
Laravel Stats
📈 Get insights about your Laravel or Lumen Project
Stars: ✭ 1,386 (-9.11%)
Mutual labels:  laravel-package
Laravel Google Translate
This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 97 (-93.64%)
Mutual labels:  laravel-package
Minecraft Avatar
PHP script (using GD) to generate avatar or skin from a Minecraft username
Stars: ✭ 104 (-93.18%)
Mutual labels:  avatar
Lara Lens
Laravel package for display diagnostic (config, database, http connections...)
Stars: ✭ 96 (-93.7%)
Mutual labels:  laravel-package
Nova Indicator Field
A colour-coded indicator field for Laravel Nova
Stars: ✭ 108 (-92.92%)
Mutual labels:  laravel-package
Admin One Laravel Dashboard
Admin One — Free Laravel Dashboard (Bulma Buefy Vue.js SPA)
Stars: ✭ 94 (-93.84%)
Mutual labels:  laravel-package
Thispersondoesnotexist Js
Api for https://thispersondoesnotexist.com Generates an image of a person that does not exist in real life
Stars: ✭ 101 (-93.38%)
Mutual labels:  avatar
Laravel Excel
🚀 Supercharged Excel exports and imports in Laravel
Stars: ✭ 10,417 (+583.08%)
Mutual labels:  laravel-package
Elasticsearch Eloquent
⚡️ Eloquent models for Elasticsearch.
Stars: ✭ 100 (-93.44%)
Mutual labels:  laravel-package

laravolt/avatar

Total Downloads Monthly Downloads Travis Coverage Status

Preview

Display unique avatar for any user based on their (initials) name.

Preview

Preview

Installation

This package originally built for Laravel, but can also be used in any PHP project.

Read more about integration with PHP project here.

Laravel >= 5.2:

composer require laravolt/avatar

Laravel 5.1:

composer require laravolt/avatar ~0.3

Service Provider & Facade

Note: only for Laravel 5.4 and below, because since Laravel 5.5 we use package auto-discovery.

Laravolt\Avatar\ServiceProvider::class,

...

'Avatar'    => Laravolt\Avatar\Facade::class,

Publish Config (optional)

php artisan vendor:publish --provider="Laravolt\Avatar\ServiceProvider"

This will create config file located in config/laravolt/avatar.php.

Lumen Service Provider

$app->register(Laravolt\Avatar\LumenServiceProvider);

Usage

Output as base64

//this will output data-uri (base64 image data)
//something like data:image/png;base64,iVBORw0KGg....
Avatar::create('Joko Widodo')->toBase64();

//use in view
//this will display initials JW as an image
<img src="{{ Avatar::create('Joko Widodo')->toBase64() }}" />

Save as file

Avatar::create('Susilo Bambang Yudhoyono')->save('sample.png');
Avatar::create('Susilo Bambang Yudhoyono')->save('sample.jpg', 100); // quality = 100

Output as Gravatar

Avatar::create('[email protected]')->toGravatar();
// Output: http://gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879

Avatar::create('[email protected]')->toGravatar(['d' => 'identicon', 'r' => 'pg', 's' => 100]);
// Output: http://gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?d=identicon&r=pg&s=100

Gravatar parameter reference: https://en.gravatar.com/site/implement/images/

Output as SVG

Avatar::create('Susilo Bambang Yudhoyono')->toSvg();

You may specify custom font-family for your SVG text.

<head>
    <!--Prepare custom font family, using Google Fonts-->
    <link href="https://fonts.googleapis.com/css?family=Laravolt" rel="stylesheet">

    <!--OR-->

    <!--Setup your own style-->
    <style>
    @font-face {
        font-family: Laravolt;
        src: url({{ asset('fonts/laravolt.woff')) }});
    }
    </style>
</head>
Avatar::create('Susilo Bambang Yudhoyono')->setFontFamily('Laravolt')->toSvg();

Get underlying Intervention image object

Avatar::create('Abdul Somad')->getImageObject();

The method will return an instance of Intervention image object, so you can use it for further purposes.

Non-ASCII Character

By 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.

Alternatively, we can convert all non-ascii to their closest ASCII counterparts. If no closest coutnerparts found, those characters are removed. Thanks to Stringy for providing such useful functions. What we need is just change one line in config/avatar.php:

    'ascii'    => true,

Configuration

<?php
/*
 * Set specific configuration variables here
 */
return [

    /*
    |--------------------------------------------------------------------------
    | Image Driver
    |--------------------------------------------------------------------------
    | Avatar use Intervention Image library to process image.
    | Meanwhile, Intervention Image supports "GD Library" and "Imagick" to process images
    | internally. You may choose one of them according to your PHP
    | configuration. By default PHP's "Imagick" implementation is used.
    |
    | Supported: "gd", "imagick"
    |
    */
    'driver'    => 'gd',

    // Initial generator class
    'generator' => \Laravolt\Avatar\Generator\DefaultGenerator::class,

    // Whether all characters supplied must be replaced with their closest ASCII counterparts
    'ascii'    => false,

    // Image shape: circle or square
    'shape' => 'circle',

    // Image width, in pixel
    'width'    => 100,

    // Image height, in pixel
    'height'   => 100,

    // Number of characters used as initials. If name consists of single word, the first N character will be used
    'chars'    => 2,

    // font size
    'fontSize' => 48,

    // convert initial letter in uppercase
    'uppercase' => false,

    // Right to Left (RTL)
    'rtl' => false,

    // Fonts used to render text.
    // If contains more than one fonts, randomly selected based on name supplied
    'fonts'    => [__DIR__.'/../fonts/OpenSans-Bold.ttf', __DIR__.'/../fonts/rockwell.ttf'],

    // List of foreground colors to be used, randomly selected based on name supplied
    'foregrounds'   => [
        '#FFFFFF',
    ],

    // List of background colors to be used, randomly selected based on name supplied
    'backgrounds'   => [
        '#f44336',
        '#E91E63',
        '#9C27B0',
        '#673AB7',
        '#3F51B5',
        '#2196F3',
        '#03A9F4',
        '#00BCD4',
        '#009688',
        '#4CAF50',
        '#8BC34A',
        '#CDDC39',
        '#FFC107',
        '#FF9800',
        '#FF5722',
    ],

    'border'    => [
        'size'  => 1,

        // border color, available value are:
        // 'foreground' (same as foreground color)
        // 'background' (same as background color)
        // or any valid hex ('#aabbcc')
        'color' => 'background',

        // border radius, only works for SVG
        'radius' => 0,
    ],

    // List of theme name to be used when rendering avatar
    // Possible values are:
    // 1. Theme name as string: 'colorful'
    // 2. Or array of string name: ['grayscale-light', 'grayscale-dark']
    // 3. Or wildcard "*" to use all defined themes
    'theme' => ['*'],

    // Predefined themes
    // Available theme attributes are:
    // shape, chars, backgrounds, foregrounds, fonts, fontSize, width, height, ascii, uppercase, and border.
    'themes' => [
        'grayscale-light' => [
            'backgrounds' => ['#edf2f7', '#e2e8f0', '#cbd5e0'],
            'foregrounds' => ['#a0aec0'],
        ],
        'grayscale-dark' => [
            'backgrounds' => ['#2d3748', '#4a5568', '#718096'],
            'foregrounds' => ['#e2e8f0'],
        ],
        'colorful' => [
            'backgrounds' => [
                '#f44336',
                '#E91E63',
                '#9C27B0',
                '#673AB7',
                '#3F51B5',
                '#2196F3',
                '#03A9F4',
                '#00BCD4',
                '#009688',
                '#4CAF50',
                '#8BC34A',
                '#CDDC39',
                '#FFC107',
                '#FF9800',
                '#FF5722',
            ],
            'foregrounds' => ['#FFFFFF'],
        ],
    ]
];

Overriding config at runtime

We can overriding configuration at runtime by using following functions:

Avatar::create('Soekarno')->setDimension(100);//width = height = 100 pixel
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'); // size = 1, color = #aabbcc
Avatar::create('Soekarno')->setBorder(1, '#aabbcc', 10); // size = 1, color = #aabbcc, border radius = 10 (only for SVG)
Avatar::create('Soekarno')->setShape('square');

// Available since 3.0.0
Avatar::create('Soekarno')->setTheme('colorful'); // set exact theme
Avatar::create('Soekarno')->setTheme(['grayscale-light', 'grayscale-dark']); // theme will be randomized from these two options

// chaining
Avatar::create('Habibie')->setDimension(50)->setFontSize(18)->toBase64();

Integration with other PHP project

// include composer autoload
require 'vendor/autoload.php';

// import the Avatar class
use Laravolt\Avatar\Avatar;

// create your first avatar
$avatar = new Avatar($config);
$avatar->create('John Doe')->toBase64();
$avatar->create('John Doe')->save('path/to/file.png', $quality = 90);

$config is just an ordinary array with same format as explained above (See Configuration).

Support Us

Buy Me A Coffee

"Buy Me A Coffee"

Donate Via PayPal

paypal

Traktir Saya

Trakteer Saya

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].