ranvis/identicon

具有可变复杂度的Identicon。

v1.0.2 2022-01-11 13:37 UTC

This package is auto-updated.

Last update: 2024-09-24 10:33:45 UTC


README

具有可变复杂度的Identicon。

示例

https://github.com/ranvis/identicon/wiki/Samples

许可证

BSD 2-Clause License

安装

composer require ranvis/identicon:1.0.*

1.1或更高版本可能与1.0存在视觉不兼容。

升级

1.0.x与1.0.0完全兼容。

有关详细信息,请参阅CHANGES.md

示例用法

use Ranvis\Identicon;

require_once __DIR__ . '/vendor/autoload.php';

//$hash = md5($userId . 'YOUR_RANDOM_SALT_HERE_&ar/1R#S[|=hDF');

$hash = $_GET['hash'] ?? '';
//$hash = isset($_GET['hash']) ? $_GET['hash'] : ''; // PHP 5
if (!preg_match('/\A[0-9a-f]{32}\z/', $hash)) {
    http_response_code(404);
    exit;
}

$tile = new Identicon\Tile();
$identicon = new Identicon\Identicon(64, $tile);
header('Cache-Control: public, max-age=31556952');
$identicon->draw($hash)->output();

快速参考

Identicon::__construct()

__construct($maxSize, TileInterface $tile, $tiles = 6, $colors = 2, $highQuality = true)

  • int $maxSize 要绘制的图标最大大小
  • TileInterface $tile 要使用的瓦片
  • int $tiles 图标的复杂度
  • int $colors 可用颜色的最大数量
  • bool $highQuality 更偏好质量而非内存和速度

Identicon->getMinimumHashLength()

getMinimumHashLength(): int

获取绘制图标所需的十六进制字符数。

Identicon->draw()

draw($hash): $this

将图标绘制到内部缓冲区。

  • string $hash 任意十六进制字符串

返回 $this。

Identicon->output()

output($size = null, $compression = -1, $filters = -1): bool

以Content-Type头将PNG图像打印到标准输出。

  • int $size 图像大小
  • int $compression PNG压缩级别
  • int $filters 要使用的PNG过滤器标志

成功时返回true。

Identicon->save()

save($filePath, $size = null, $compression = -1, $filters = -1): bool

将PNG图像保存到文件。

  • string $filePath 保存的文件路径
  • int $size 图像大小
  • int $compression PNG压缩级别
  • int $filters 要使用的PNG过滤器标志

成功时返回true。

Identicon->getImage()

getImage($size = null): resource

获取图标图像。

  • int $size 图像大小

返回GD图像。