yzalis/identicon 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

yzalis/identicon

最新稳定版本:2.0.0

Composer 安装命令:

composer require yzalis/identicon

包简介

Create awesome unique avatar.

README 文档

README

Build Status codecov.io

Identicon is a library which generate an identicon image based on a string.

Here is some examples of awesome results!

Identicon example #1   Identicon example #2   Identicon example #3   Identicon example #4   Identicon example #5

Installation

The recommended way to install Identicon is through composer.

Just add the library to your project:

composer require yzalis/identicon

Usage

Images are generated in PNG format with transparent background.

The string can be an email, an IP address, a username, an ID or something else.

Generate an identicon

Create a new Identicon object.

$identicon = new \Identicon\Identicon();

Then you can generate and display an identicon image

$identicon->displayImage('foo');

or generate and get the image data

$imageData = $identicon->getImageData('bar');

or generate and get the base 64 image uri ready for integrate into an HTML img tag.

$imageDataUri = $identicon->getImageDataUri('bar');
<img src="<?php echo $imageDataUri; ?>" alt="bar Identicon" />

Change the size

By default the size will be 64 pixels. If you want to change the image size just add a secondary parameter. 512 x 512px in this example.

$identicon->displayImage('foo', 512);

Color

The color is automatically generated according to the string hash but you can chose to specify a color by adding a third argument.

Color can be an hexadecimal with 6 characters

$identicon->displayImage('bar', 64, 'A87EDF');

or an array with red, green, blue value

$identicon->displayImage('foo', 64, array(200, 100, 150));

That's it!

Generate an identicon on SVG format

The only thing you need to change it this one:

$identicon = new \Identicon\Identicon(new SvgGenerator());
$imageDataUri = $identicon->getImageDataUri('bar');
<img src="<?= $imageDataUri; ?>" alt="bar Identicon" />

Unit Tests

To run unit tests, you'll need and a set of dependencies you can install using Composer:

php composer.phar install

Once installed, just launch the following command:

./vendor/bin/phpunit

Everything should be ok.

Credits

Inspired by Github blog post about Identicon.

License

Identicon is released under the MIT License. See the bundled LICENSE file for details.

统计信息

  • 总下载量: 1.02M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 589
  • 点击次数: 1
  • 依赖项目数: 25
  • 推荐数: 0

GitHub 信息

  • Stars: 579
  • Watchers: 15
  • Forks: 94
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-15