lincanbin/material-design-avatars

为Android用户创建类似Gmail或Messager的材料设计头像。

1.4 2017-11-04 08:21 UTC

This package is auto-updated.

Last update: 2024-08-28 22:37:23 UTC


README

为用户创建类似Google Messager的材料设计头像。

它可能不是独一无二的,但比Identicon或Gravatar看起来更好。

在线演示

语言支持

ENGLISH

JTZW

FTZW

RIYU

屏幕截图

Carbon论坛

Carbon Forum

Carbon论坛的Android客户端

Android Client for Carbon Forum

要求

初始化

<?php
require(dirname(__FILE__) . "/src/MDAvatars.php");
/*
'X'         : The character that you want to fill to the avatar.
512 (pixel) : The size of the avatar.
*/
$Avatar = new Md\MDAvatars('X', 512);
?>

或者使用Composer初始化

{
	"require": {
		"lincanbin/material-design-avatars": "*.*"
	}
}
<?php
// composer 
require(__DIR__ . "/vendor/autoload.php");
use Md\MDAvatars;

$Avatar = new MDAvatars('X', 512);
?>

使用方法

在浏览器中显示头像

<?php
$Avatar->Output2Browser();
?>
<?php
// You can resize the ouput size again here.
$OutputSize = 256;
$Avatar->Output2Browser($OutputSize);
// Output Base64 encoded image data.
$Avatar->Output2Base64($OutputSize);
// Get an image resource identifier.
$Avatar->Output2ImageResource($OutputSize);
?>

将头像保存到文件

<?php
$Avatar->Save('./avatars/Avatar.png');
//You can resize the size you want to save again here.
$Avatar->Save('./avatars/Avatar256.png', 256);
$Avatar->Save('./avatars/Avatar128.png', 128);
$Avatar->Save('./avatars/Avatar64.png', 64);
?>

释放内存

<?php
$Avatar->Free();
?>

注意

如果您不需要中文支持,您可以删除 src/fonts/SourceHanSansCN-Normal.ttf

当您输入中文字符时,如果删除了 src/fonts/SourceHanSansCN-Normal.ttf,它将自动提取中文字符拼音的第一个字母,而不是原始输入。

$Avatar = new MDAvtars('', 512);//The pinyin of "林" is "Lin".

如果删除了 src/fonts/SourceHanSansCN-Normal.ttf,这将是以下内容相同。

$Avatar = new MDAvtars('L', 512);//The first letter of that pinyin is "Lin".

字体

Source Code Pro

Source Han Sans

许可证

Copyright 2015 Canbin Lin (lincanbin@hotmail.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.