maxvoronov / avatarix
头像生成库
0.1.0
2018-08-05 03:22 UTC
Requires
- php: ^7.0
- imagine/imagine: ^0.7.1
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-24 17:09:00 UTC
README
安装
安装此扩展的首选方式是通过 composer
composer require maxvoronov/avatarix
使用方法
该库可以生成由任意字符串生成的8位头像。本包使用 Imagine 进行处理。
use MaxVoronov\Avatarix; use MaxVoronov\Avatarix\SpriteCollection; $avatarix = new Avatarix; $avatarix->setPayload('username'); // You can use here user ID or email $avatarix // Set collections of avatar parts ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/bg/')) ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/faces/')) ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/clothes/')) ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/mouths/')) ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/eyes/')) ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/hairs/')); $userAvatar = $avatarix->render(); $userAvatar->save('/path/to/avatar.png'); // Save generated avatar into file $userAvatar->show('png'); // ... and output with image headers
您还可以查看 示例。
特别感谢
特别感谢 @matveyco 和他的 8biticon 项目 为头像精灵提供的支持。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。