robinn/svg-avatar

根据用户姓名创建独特的头像。

1.2.1 2023-08-17 20:39 UTC

This package is auto-updated.

Last update: 2024-09-27 10:47:32 UTC


README

根据用户姓名创建独特的头像。

Preview

Visitor Badge

安装

composer require robinn/svg-avatar

用法

use RobiNN\SVGAvatar\SVGAvatar;

$avatar = new SVGAvatar();

echo $avatar->name('RobiNN');

如果您没有设置名称,将显示用户图标。这可以用于访客。

方法

// Custom size, default is 48px.
$avatar->size(64);

// Display as a circle.
$avatar->circle();

// Border radius.
$avatar->radius(10);

// CSS class.
$avatar->class('avatar');

// Custom colors. By default, background colors are generated from name.
$avatar->setColors(['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',]);
// You can set the text color if needed. The default is 'auto' which sets '#fff' or '#000'.
$avatar->setColors([...], '#000');

// Color brightness, between 0-100, default is 50. Doesn't work with setColors().
$avatar->brightness(80);

// Color uniqueness, between 1-10, 3 is default. Doesn't work with setColors().
$avatar->uniqueness(7);

// Output as base64
$avatar->toBase64();

要求

  • PHP >= 8.2
  • mbstring 扩展