stnw/avatar-bundle

此包最新版本(dev-master)没有提供许可证信息。

一个简单的 Symfony 包,用于生成头像。

安装: 45

依赖: 0

建议者: 0

安全: 0

星星: 3

关注者: 0

分支: 1

开放问题: 0

类型:symfony-bundle

dev-master 2013-04-15 16:06 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:17:40 UTC


README

这是一个简单的 Symfony2 包,用于生成头像。提供男性与女性头像的版本、尺寸、保存或输出到浏览器等配置。已包含头像模板。您还可以添加/更改模板。

安装

  1. 将此包添加到您的 debs 文件中。

     [StnwAvatarBundle]
        git=https://github.com/stnw/StnwAvatarBundle
        target=/bundles/Stnw/AvatarBundle
    
  2. 将以下依赖项添加到项目的 composer.json 文件中

     "require": {
       // ...
       "stnw/avatar-bundle": "dev-master"
       // ...
     }
    

Stnw 命名空间到自动加载器

      // app/autoload.php
      $loader->registerNamespaces(array(
         'Stnw' => __DIR__ . '/../vendor/bundles',
         // your other namespaces
      );
  1. 将此包添加到应用程序内核

     // app/AppKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new Stnw\AvatarBundle\AvatarBundle(),
             // ...
         );
     }
    
  2. 更新 vendors

     php bin/vendors update
    
  3. 如果您想更改默认头像模板,请在配置中配置 stnw_avatar 服务

     # application/config/config.yml
     stnw_avatar:
       avatar.folder:  #path to the folder with male & female templates folders
       avatar.male_folders: [face, hair, nose, eye, mouth] #folders with templates. From every folder one png file will be  a layer for avatar.
       avatar.female_folders: [hair, face, nose, eye, mouth]
    

使用方法

在文件夹中生成头像

      $avatarManager = $this->get('avatar.manager');
      $avatarPach = $this->get('kernel')->getRootDir() . '/../web/avatar.png';
      $result = $avatarManager->generateAvatar($avatarPach);

或使用参数

      $result = $avatarManager->generateAvatar($avatarPath, 'female', 100);

唯一必须的参数是新的头像路径。其余参数都有默认值。