五人组/identicon

一个用于生成identicon的PHP库。

维护者

详细信息

github.com/fivenp/identicon

源代码

安装: 11

依赖: 0

建议: 0

安全: 0

星星: 1

关注者: 2

分支: 0

0.2.3 2018-03-22 09:43 UTC

This package is not auto-updated.

Last update: 2024-09-21 05:53:18 UTC


README

PHP-Identicons是Don Park原始identicon代码的轻量级PHP实现,用于MD5哈希值的视觉表示。该程序使用PHP GD库进行图像处理。

代码可用于根据用户的电子邮件地址、用户ID等生成唯一的identicon、头像和系统分配的图像。

安装

使用composer安装

$ composer require fivenp/identicon

用法

基本用法

以下代码将从字符串"TEST"创建一个identicon,并将其保存到identicon.png中。

<?php

use Fivenp\Identicon\Identicon;

$identicon = new Identicon(md5('TEST'));
$icon = $identicon->create();
file_put_contents('identicon.png', $icon);

还有更简短的方式来做这件事

<?php

use Fivenp\Identicon\Identicon;

file_put_contents('identicon.png', (new Identicon(md5('TEST')))->create());

高级用法

您可以通过传递一个options数组来覆盖一些基本设置。

<?php

use Fivenp\Identicon\Identicon;

$options = array(
    'size'=>2048, // a value between 16 and 2048 is accepted
    'backgroundColor'=>array( // must be in red/green/blue
        "red" => "255",
        "green" => "255",
        "blue" => "255",
    ),
);

$identicon = new Identicon(md5('TEST'),$options);
$icon = $identicon->create();

更高级的选项

您还可以覆盖一些更高级的设置

<?php

use Fivenp\Identicon\Identicon;

$options = array(
    'size'=>2048, // a value between 16 and 2048 is accepted
);

$identicon = new Identicon(md5('TEST'),$options);

// A cusom color palette where the generator is using the colors randomly from
$identicon->palette = array(
    'orange' => '#ff944e',
    'red' => '#e84c3d',
    'blue' => '#3598db',
    'black' => '#000000',
    'white' => '#ffffff',
);

// A cusom color palette where the generator is using the backgroundColor randomly from
$identicon->availableBackgroundColors = array(
    'white',
    'red',
);

$icon = $identicon->create();

许可证

PHP-Identicons在GPLv3许可证下分发。

历史

此代码是从Timo van Neerden的GitHub项目页面分叉的,最初由Bong Costa在2009年创建。

它已从其SourceForge项目页面分叉,因为我打算对其进行一些增强以供个人使用。