phalapi / material-design-avatars
为用户创建类似 Gmail 或 Android 消息应用的材料设计头像。
1.4
2017-11-04 08:21 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-19 16:10:14 UTC
README
为用户创建类似 Google 消息应用的材料设计头像。
它可能不是独一无二的,但比 Identicon 或 Gravatar 看起来更好。
语言支持
截图
要求
- PHP 的 GD 库。
初始化
<?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".
字体
许可证
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.