Identicon
Identicon 会在带色调的背景上,以单一颜色呈现对称的像素网格图案,这种经典的 Identicon 外观因开发者工具和版本控制托管平台而广为人知。每种图案都根据其种子 确定性地生成,因此非常适合技术类个人资料图标和 Identicon API 使用场景。
Preview
什么是 identicon?
Identicon 是根据用户名、电子邮件或用户 ID 等值生成的小型图像。同一个输入始终会生成相同的图片,因此人们可以一眼认出某个账户,也不必上传照片。GitHub 将其作为默认头像而广为人知,许多开发者工具也采用了相同的做法。DiceBear 的 Identicon 样式同样如此:它会对种子值进行哈希处理并绘制对称网格,因此你可以将其用作个人资料图标和占位头像的 identicon 生成器。
用法
Use this URL to request this avatar style via our HTTP API.
https://api.dicebear.com/10.x/identicon/svgYou can use the URL directly as image source.
<img
src="https://api.dicebear.com/10.x/identicon/svg"
alt="avatar"
/>See HTTP-API docs for more information.
First install the required packages via npm:
npm install @dicebear/core @dicebear/styles --saveThen you can create this avatar as follows:
import { Style, Avatar } from '@dicebear/core';
import definition from '@dicebear/styles/identicon.json' with { type: 'json' };
const style = new Style(definition);
const avatar = new Avatar(style, {
// ... options
});
const svg = avatar.toString();
See JS docs for more information.
First install the required packages via Composer:
composer require dicebear/core dicebear/stylesThen you can create this avatar as follows:
<?php
use Composer\InstalledVersions;
use DiceBear\Style;
use DiceBear\Avatar;
$basePath = InstalledVersions::getInstallPath('dicebear/styles');
$style = Style::fromJson(file_get_contents($basePath . '/src/identicon.json'));
$avatar = new Avatar($style, [
// ... options
]);
$svg = (string) $avatar;
See PHP docs for more information.
First install the required packages via pip:
pip install dicebear-core dicebear-stylesThen you can create this avatar as follows:
from importlib.resources import files
from dicebear import Avatar, Style
style = Style.from_json(
files("dicebear_styles").joinpath("identicon.json").read_text("utf-8")
)
avatar = Avatar(style, {
# ... options
})
svg = avatar.to_string()
See Python docs for more information.
First add the required crates via Cargo:
cargo add dicebear-core serde_json
cargo add dicebear-styles --features identiconThen you can create this avatar as follows:
use dicebear_core::{Avatar, Style};
use serde_json::json;
let style = Style::from_str(dicebear_styles::IDENTICON)?;
let avatar = Avatar::new(&style, json!({
// ... options
}))?;
let svg = avatar.to_svg();
See Rust docs for more information.
First add the required modules with go get:
go get github.com/dicebear/dicebear-go/v10
go get github.com/dicebear/styles/v10Then you can create this avatar as follows:
import (
dicebear "github.com/dicebear/dicebear-go/v10"
"github.com/dicebear/styles/v10"
)
style, _ := dicebear.NewStyle([]byte(styles.Identicon))
avatar, _ := dicebear.NewAvatar(style, map[string]any{
// ... options
})
svg := avatar.SVG()
See Go docs for more information.
First add the required packages with dart pub:
dart pub add dicebear_core dicebear_stylesThen you can create this avatar as follows:
import 'package:dicebear_core/dicebear_core.dart';
import 'package:dicebear_styles/identicon.dart';
final style = Style.parse(identicon);
final avatar = Avatar(style, {
// ... options
});
final svg = avatar.svg;
See Dart docs for more information.
First install the CLI package via npm:
npm install --global dicebearThen you can create this avatar as follows:
dicebear identiconSee CLI docs for more information.
选项
详情
Naming
| Definition Import | |
| CLI | |
| HTTP-API | https://api.dicebear.com/10.x/identicon/svg |
| Definition | https://cdn.hopjs.net/npm/@dicebear/styles@10.4.0/dist/identicon.min.json |
Source
| Title | Identicon |
| Creator | DiceBear |
| Website | https://www.dicebear.com |
| License | CC0 1.0 |
| Source | https://www.dicebear.com |