承接 usarise/identicon 相关项目开发

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

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

usarise/identicon

最新稳定版本:0.8.2

Composer 安装命令:

composer require usarise/identicon

包简介

A PHP library for generating identicons.

README 文档

README

Latest Version PHP Version License Total Downloads GitHub CI

Based and inspired on

test

Installation

composer require usarise/identicon

Usage browser

<?php

declare(strict_types=1);

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

use Usarise\Identicon\Identicon;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

$identicon = new Identicon(
    new SvgCanvas(),
    420,
);

$response = $identicon->generate('test');

header("Content-type: {$response->mimeType}");
echo (string) $response;

Usage write file

<?php

declare(strict_types=1);

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

use Usarise\Identicon\Identicon;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

$identicon = new Identicon(
    new SvgCanvas(),
    420,
);

$response = $identicon->generate('test');
$response->save("test.{$response->format}");

Usage data url

<?php

declare(strict_types=1);

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

use Usarise\Identicon\Identicon;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

$identicon = new Identicon(
    new SvgCanvas(),
    420,
);

$response = $identicon->generate('test');
$data = sprintf(
    'data:%s;base64,%s',
    $response->mimeType,
    base64_encode(
        (string) $response,
    ),
);
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Identicon Data URL example</title>
</head>
<body>
  <img src="<?php echo $data; ?>" />
</body>
</html>

Usage advanched

Construct

use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;
use Usarise\Identicon\{Identicon, Resolution};

$identicon = new Identicon(
    image: new SvgCanvas(), // implementation Usarise\Identicon\Image\CanvasInterface
    size: 420, // 420x420 pixels
    resolution: Resolution::Medium, // Resolution 10x10 (Default)
);

Image Canvas

Implementations Usarise\Identicon\Image\CanvasInterface from the box

use Usarise\Identicon\Image\Gd\Canvas as GdCanvas;
use Usarise\Identicon\Image\Imagick\Canvas as ImagickCanvas;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

Gd extension (GD Library)

new GdCanvas()

Imagick extension (ImageMagick)

new ImagickCanvas()

SVG

new SvgCanvas()

Size

Output image height and width

Must be a positive multiple of the resolution

Example: 120 for resolution Resolution::Medium and 126 for resolution Resolution::Large

Resolutions

Pixel resolution of the pattern identicon

use Usarise\Identicon\Resolution;

6x6 (Tiny)

Tiny

Resolution::Tiny

8x8 (Small)

Small

Resolution::Small

10x10 (Medium)

Medium

Resolution::Medium

12x12 (Large)

Large

Resolution::Large

14x14 (Huge)

Huge

Resolution::Huge

Generate

String

Username, id, email, ip, etc

$response = $identicon->generate(string: 'test')

Background

CSS 6-digit or 3-digit hex color

$response = $identicon->generate(string: 'test', background: '#f2f1f2')

Foreground

CSS 6-digit or 3-digit hex color

$response = $identicon->generate(string: 'test', foreground: '#84c7b5')

Background and Foreground

CSS 6-digit or 3-digit hex color

$response = $identicon->generate(string: 'test', background: '#f2f1f2', foreground: '#84c7b5')

Response

Format

png, svg, other custom

$response->format // svg

Mime type

image/png, image/svg+xml, other custom

$response->mimeType // image/svg+xml

Output string

Compressed image

$response->output

Alternative $response->output: response object to string

Compressed image

(string) $response

Uncompressed image

object, string, null

$response->image // object

Save file

Allowed file extension only $response->format

$response->save(path: __DIR__ . '/test.svg')

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unlicense
  • 更新时间: 2023-05-08