public static function materialAvatar(string $name, float $dimensions = 100, string $color = null) : string
    {
        $letter = mb_substr($name, 0, 1, 'utf-8');

        if (!$color) {
            $color = static::materialColors()->random();
        } else {
            $color = static::materialColors($color);
        }

        $text_position = bcdiv($dimensions, 2, 2);
        $cache_key = "support__material_avatar:{$letter}_{$dimensions}_{$color}";

        if (!Cache::has($cache_key)) {
            $image = Image::canvas($dimensions, $dimensions, $color)
                ->text($letter, $text_position, $text_position, function ($font) use ($dimensions) {
                    $font->file(__DIR__ . '/../Assets/fonts/Roboto-Light.ttf')
                        ->size(bcdiv($dimensions, 1.75, 2))
                        ->color('#ffffff')
                        ->align('center')
                        ->valign('middle');
                })
                ->encode('data-url');
            Cache::put($cache_key, $image);
            return $image;
        }

        return Cache::get($cache_key);
    }
public static function materialAvatar(string $name, float $dimensions = 100, string $color = null) : string
    {
        $letter = mb_substr($name, 0, 1, 'utf-8');

        if (!$color) {
            $color = static::materialColors()->random();
        } else {
            $color = static::materialColors($color);
        }

        $text_position = bcdiv($dimensions, 2, 2);
        $cache_key = "support__material_avatar:{$letter}_{$dimensions}_{$color}";

        if (!Cache::has($cache_key)) {
            $image = Image::canvas($dimensions, $dimensions, $color)
                ->text($letter, $text_position, $text_position, function ($font) use ($dimensions) {
                    $font->file(__DIR__ . '/../Assets/fonts/Roboto-Light.ttf')
                        ->size(bcdiv($dimensions, 1.75, 2))
                        ->color('#ffffff')
                        ->align('center')
                        ->valign('middle');
                })
                ->encode('data-url');
            Cache::put($cache_key, $image);
            return $image;
        }

        return Cache::get($cache_key);
    }
public static function materialAvatar ( string $ name , float $ dimensions = 100 , string $ color = null ) : string { $ letter = mb_substr ( $ name , 0 , 1 , 'utf-8' ) ; if ( ! $ color ) { $ color = static :: materialColors ( ) -> random ( ) ; } else { $ color = static :: materialColors ( $ color ) ; } $ text_position = bcdiv ( $ dimensions , 2 , 2 ) ; $ cache_key = "support__material_avatar:{$letter}_{$dimensions}_{$color}" ; if ( ! Cache :: has ( $ cache_key ) ) { $ image = Image :: canvas ( $ dimensions , $ dimensions , $ color ) -> text ( $ letter , $ text_position , $ text_position , function ( $ font ) use ( $ dimensions ) { $ font -> file ( __DIR__ . '/../Assets/fonts/Roboto-Light.ttf' ) -> size ( bcdiv ( $ dimensions , 1.75 , 2 ) ) -> color ( '#ffffff' ) -> align ( 'center' ) -> valign ( 'middle' ) ; } ) -> encode ( 'data-url' ) ; Cache :: put ( $ cache_key , $ image ) ; return $ image ; } return Cache :: get ( $ cache_key ) ; }
Returns a material design avatar for the given data.

@author Erik Campobadal Fores <soc@erik.cat>
@copyright 2017 erik.cat
@param string $name
@param float|integer $dimensions
@param string|null $color
@return string
Returns a material design avatar for the given data .