承接 fabian-tomischka/php-avatar-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fabian-tomischka/php-avatar-generator

Composer 安装命令:

composer require fabian-tomischka/php-avatar-generator

包简介

Easily create user avatars based on provided names or strings

README 文档

README

Display unique avatars based on the initials of your users names. Easy to use with loads of options to extend by yourself.

Images

Installation

Require from composer and start using it!

composer require fabian-tomischka/php-avatar-generator

Usage

Quick-start with a simple line of code

use Fabito\AvatarGenerator\Avatar;

$generator = new Avatar();
$avatar = $generator->name('Fabian Tomischka')->toJpeg();

You can also use a string instead of a given name. However, when providing a string, it will ignore any given whitespaces and always take the characters from the string directly.

// Will result in Fa on the avatar instead of FT
$avatar = $generator->string('Fabian Tomischka')->toJpeg();

You can also access the image manager or canvas of the underlying Intervention/Image in case you need it

$manager = $generator->getImageManager();
$canvas = $generator->name('Fabian Tomischka')->getImageCanvas();

Customizing

The package offers multiple ways of adjusting and tweaking the settings.

driver('driver')

The driver which is used for generating the images. Currently supported: gd and imagick. Default: gd

$avatar = $generator->driver($generator::DRIVER_IMAGICK)->toBase64();

height('px'), width('px'), size('px'), dimensions('width', 'height')

Change the dimensions of the avatar. Usually size will do the job. Default: 100px

$avatar = $generator->size(100)->toBase64();

backgroundColor('color')

In case you do not want to use the default colors provided by the package you can manually set the color here

$avatar = $generator->backgroundColor('#000000')->toBase64();

fontColor('color')

Change the font color. Default: #F7F7F7

$avatar = $generator->fontColor('#000000')->toBase64();

fontSize('px')

Change the font size on the avatar. Default: 42px

$avatar = $generator->fontSize(42)->toBase64();

length('int')

In case you require less or more characters to be on the avatar. Default: 2

// Output: F
$avatar = $generator->name('Fabian Tomischka')->length(1)->toBase64();
$avatar = $generator->string('FT')->length(1)->toBase64();

Loading custom fonts

By default, the package comes with pre-installed OpenSans Light and Regular fonts. They usually do the job. In case you want to change your font, you can do that by calling the font method and providing a path to the new font:

$avatar = $generator->font('/dir/to/the/font.ttf')->name('Fabian Tomischka')->toBase64();

Make sure that the font is available as TTF!

Getting image data

For easy access the package offers multiple direct methods to access the image in different file formats.

$avatar = $generator->name('Fabian Tomischka')->toBase64(); // Base 64
$avatar = $generator->name('Fabian Tomischka')->toPng(); // PNG
$avatar = $generator->name('Fabian Tomischka')->toJpeg(); // JPEG
$avatar = $generator->name('Fabian Tomischka')->toWebp; // WebP

As mentioned above, in case you need access to the underlying manager or image, you can access them via

$manager = $generator->getImageManager();
$canvas = $generator->name('Fabian Tomischka')->getImageCanvas();

Rounded avatars

The package potentially offers you an option to generate rounded avatars.

$avatar = $generator->rounded()->name('Fabian Tomischka')->toBase64();

However I do highly suggest using border radius in CSS to display your avatar as a circle. Generating rounded avatars will always result in a lower quality.

Requirements

  • PHP 7.1.7 or higher
  • Intervention/Image 2.4 or higher
  • Imagick extension (in case you do not use the default GD)

统计信息

  • 总下载量: 1.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-08-27