2017 © Pedro Peláez
 

symfony-bundle avatar-bundle

Simply Symfony 3.x & Symfony 2.x bundle which creates avatars images using GD.

image

dwr/avatar-bundle

Simply Symfony 3.x & Symfony 2.x bundle which creates avatars images using GD.

  • Friday, March 10, 2017
  • by dwr
  • Repository
  • 1 Watchers
  • 4 Stars
  • 6,167 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 9 % Grown

The README.md

SensioLabsInsight

License Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Coverage Status, (*1)

DwrAvatarBundle

This bundle provides easy image avatar generator support for Symfony2 and Symfony3., (*2)

Example of avatars:, (*3)

plainAvatars:, (*4)

plainAvatar example #1   plainAvatar example #2   plainAvatar example #3  , (*5)

profileAvatars:, (*6)

profileAvatar example #1   profileAvatar example #2   profileAvatar example #3  , (*7)

In order to generate Avatar you can:, (*8)

In Controller, (*9)

``` php public function indexAction() {, (*10)

    $avatar = new AvatarFactory();

    //for plainAvatar
    $plainAvatar = $avatar->generate(new PlainAvatar(140, 140)); 

    //for profileAvatar
    $profileAvatar = $avatar->generate(new ProfileAvatar(140, 140));

    return array(
        'plainAvatar'   => $plainAvatar->render()
        'profileAvatar' => $profileAvatar->render()
    );
}

And in a **view** file (twig): ``` jinja <img src="data:image/jpg;base64,{{ plainAvatar }}" > <img src="data:image/jpg;base64,{{ profileAvatar }}" >

Installation

Installation is a quick 3 steps process:, (*11)

  1. Download DwrAvatarBundle using composer
  2. Enable the Bundle
  3. Add routing to routing.yml in order to can open example in your browser

Step 1: Download DwrAvatarBundle using composer

Add DwrAvatarBundle in version 2.0 (for Symfony 3) in your composer.json:, (*12)

{
    "require": {
        "dwr/avatar-bundle": "2.0"
    }
}

Add DwrAvatarBundle in version 1.0 (for Symfony 2) your composer.json:, (*13)

{
    "require": {
        "dwr/avatar-bundle": "1.0"
    }
}

Download the bundle by running the command:, (*14)

``` bash $ php composer.phar require dwr/avatar-bundle, (*15)


Composer will install the bundle into your project's `vendor/dwr/avatar-bundle` directory. ### Step 2: Enable the bundle Enable the bundle in the kernel: ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Dwr\AvatarBundle\DwrAvatarBundle(), ); }

Step 3: Add routing to routing.yml in order to can open example in your browser

``` yml dwr_avatar: resource: "@DwrAvatarBundle/Controller/" type: annotation prefix: /dwr_avatarbundle, (*16)


Congratulations! You're ready to generate avatars in your symfony application. Example how PlainAvatar looks like you can find on: yours-application-url/dwr_avatarbundle/avatar . ## **Usage** ## **Generate avatar in base64 stream** **Controller** ``` php public function indexAction() { $avatar = new AvatarFactory(); //for plainAvatar $plainAvatar = $avatar->generate(new PlainAvatar(140, 140)); //for profileAvatar $profileAvatar = $avatar->generate(new ProfileAvatar(140, 140)); return array( 'plainAvatar' => $plainAvatar->render() 'profileAvatar' => $profileAvatar->render() ); }

View (twig), (*17)

``` jinja , (*18)


**Outputs** ![plainAvatar example #1](Resources/doc/plain1.jpg)&nbsp;&nbsp; ![plainAvatar example #2](Resources/doc/plain2.jpg)&nbsp;&nbsp; ![plainAvatar example #3](Resources/doc/plain3.jpg)&nbsp;&nbsp; ![profileAvatar example #1](Resources/doc/profile1.jpg)&nbsp;&nbsp; ![profileAvatar example #2](Resources/doc/profile2.jpg)&nbsp;&nbsp; ![profileAvatar example #3](Resources/doc/profile3.jpg)&nbsp;&nbsp; Example how to generate avatars in base64 stream is also stored in AvatarBundle/Controller/DefaultController.php. ## **Generate avatar and save it to file** ``` php public function indexAction() { $avatar = new AvatarFactory(); $plainAvatar = $avatar->generate(new PlainAvatar(140, 140)); return array( 'plainAvatar' => $plainAvatar->save('web/images/avatar/directory') ); }

Above example generates avatar file into directory. Directory name is passed in function save as parameter. File name will be generated automatically based on this:, (*19)

``` php $filename = date('YmdHis') . uniqid() . '.jpg';, (*20)


In order to generate avatar with your own filename you can pass filename (e.g *image.jpg*) as second argument of save method. ``` php public function indexAction() { $avatar = new AvatarFactory(); $plainAvatar = $avatar->generate(new PlainAvatar(140, 140)); return array( 'plainAvatar' => $plainAvatar->save('web/images/avatar/directory', 'image.jpg') ); }

Change log

Please see CHANGELOG for more information on what has changed recently., (*21)

Troubleshooting

  1. Make sure you have GD installed on your web server. http://php.net/manual/en/function.gd-info.php

The Versions

10/03 2017

dev-master

9999999-dev https://github.com/dariuszwrzesien/DwrAvatarBundle.git

Simply Symfony 3.x & Symfony 2.x bundle which creates avatars images using GD.

  Sources   Download

MIT

The Requires

 

The Development Requires

image avatar avatar generator

02/02 2017

dev-development

dev-development https://github.com/dariuszwrzesien/DwrAvatarBundle.git

Simply symfony 2&3 bundle which creates avatars images using GD.

  Sources   Download

MIT

The Requires

 

The Development Requires

image avatar avatar generator

02/02 2017

2.0

2.0.0.0 https://github.com/dariuszwrzesien/DwrAvatarBundle.git

Simply symfony3 bundle which creates avatars images using GD.

  Sources   Download

MIT

The Requires

 

The Development Requires

image avatar avatar generator

27/11 2014

1.0

1.0.0.0 https://github.com/dariuszwrzesien/DwrAvatarBundle.git

Simply symfony2 bundle which creates avatars images using GD.

  Sources   Download

MIT

The Requires

 

The Development Requires

image avatar avatar generator

25/10 2014

0.2

0.2.0.0 https://github.com/dariuszwrzesien/DwrAvatarBundle.git

Simply symfony2 bundle which creates avatars images using GD.

  Sources   Download

MIT

The Requires

 

The Development Requires

image avatar avatar generator

24/10 2014

0.1

0.1.0.0 https://github.com/dariuszwrzesien/DwrAvatarBundle.git

Simply symfony2 bundle which creates avatars images using GD.

  Sources   Download

MIT

The Requires

 

The Development Requires

image avatar avatar generator