laravolt/avatar

Lumen config

Closed this issue · 2 comments

The package works with Lumem but the config file is not used / loaded at all.

For lumen users, the dot notation directory thing with Laravel doesnt work so make sure to name the config file laravolt.avatar.php and also add $app->configure('laravolt.avatar') to bootstrap/app.php

In Lumen, v10 at least, had to made a different work around, to start with DatabaseSeeder.

So after the composer require... do nothing! Package says to publish whatever, it didnt work... so simply:

in seeders/DatabaseSeeder.php

use Laravolt\Avatar\Avatar as Avatar;
.....
$uuid = Str::uuid(); 
$avatar = new Avatar($this->getAvatarConf());
$img = $avatar->create('First Name Last')->save('./storage/app/public/avatars/' . $uuid . '.png', $quality = 90);

....
// Basically the file configuration. So you can change ;) 

public function getAvatarConf() {
        return [
            'driver' => env('IMAGE_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' => 'square',

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

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

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

            // font size
            'fontSize' => 96,

            // 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' => 0,

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

                // border radius, currently only work 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' => ['colorful'],

            // 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'],
                ],
                'pastel' => [
                    'backgrounds' => [
                        '#ef9a9a',
                        '#F48FB1',
                        '#CE93D8',
                        '#B39DDB',
                        '#9FA8DA',
                        '#90CAF9',
                        '#81D4FA',
                        '#80DEEA',
                        '#80CBC4',
                        '#A5D6A7',
                        '#E6EE9C',
                        '#FFAB91',
                        '#FFCCBC',
                        '#D7CCC8',
                    ],
                    'foregrounds' => [
                        '#FFF',
                    ],
                ],
            ],
        ];
    }