Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zertex committed Jun 28, 2018
0 parents commit 776e8b0
Show file tree
Hide file tree
Showing 6 changed files with 506 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
/phpunit.xml
/composer.lock
/composer.phar
28 changes: 28 additions & 0 deletions LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The BSD License (BSD)

Copyright © 2018 by Egor Oldenburger (Zertex Media) All rights reserved.

> Redistribution and use in source and binary forms, with or without modification,
> are permitted provided that the following conditions are met:
>
> Redistributions of source code must retain the above copyright notice, this
> list of conditions and the following disclaimer.
>
> Redistributions in binary form must reproduce the above copyright notice, this
> list of conditions and the following disclaimer in the documentation and/or
> other materials provided with the distribution.
>
> Neither the name of Egor Oldenburger (Zertex Media) nor the names of its
> contributors may be used to endorse or promote products derived from
> this software without specific prior written permission.
>
>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
>ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
>WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
>ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
>(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
>LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
>ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
>(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
>SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Avatar Generator

Generate avatar for user by his name, file or url.

[![Latest Stable Version](https://poser.pugx.org/zertex/avatar-generator/v/stable.png)](https://packagist.org/packages/zertex/avatar-generator)
[![Total Downloads](https://poser.pugx.org/zertex/avatar-generator/downloads.png)](https://packagist.org/packages/zertex/avatar-generator)

## Features
- PNG format
- Generate avatar by username
- Generate avatar from file or url (http only)
- Auto select background color by username
- Contrast color for text
- Font face and size customize
- Texture for background (2 available now)

## Dependencies

* PHP 7
* PHP GD

## Installation

Install with composer:

```bash
composer require zertex/avatar-generator
```

or add

```bash
"zertex/avatar-generator": "*"
```

to the require section of your `composer.json` file.

## Configuration

```php
$options = AvatarOptions::create()
->setFont('path to ttf font')
->setWidth(300)
->setFontSize(200)
->setTexturesFolder('path to textures folder')
->setImagesFolder('path to generated images folder')
->setImagesUrl('url to images folder')
->setSalt('random salt');
```

* setFont - Path to TTF font
* setWidth - Width & height avatar image file. Default: 300
* setFontSize - Font size. Default: 200
* setTexturesFolder - Path to textures folder. Used only PNG textures
* setImagesFolder - Path to image folder.
* setImagesUrl - Url for generating complete link to image
* setSalt - Random text for new image file name

## Using

Generate avatar image by username
```php
$image_src = Avatar::init('John Smith', $options, [result file name])
->username()
->texture('TEXTURE_NAME')
->text()
->get_file_name();
```
Generate avatar image from file
```php
$image_src = Avatar::init('John Smith', $options, [result file name])
->file('/path/to/file')
->texture('TEXTURE_NAME')
->text()
->get_file_name();
```
Generate avatar image from url
```php
$image_src = Avatar::init('John Smith', $options, [result file name])
->file('http://your-site.com/image.jpg')
->texture('TEXTURE_NAME')
->text()
->get_file_name();
```

You can exclude texture or text from chain for exclude them

## Textures

You can use PNG texture with transparancy.
Every texture must consist of **2 files** (back & white).
His names myst be:
```php
TEXTURE_NAME . '-' . COLOR . '.png'
```
* TEXTURE_NAME - Any words. In texture() method you can use array of TEXTURE_NAME for random
* COLOR - Must be `black` or `white`

## Screenshot

![alt text](http://zertex.ru/ext-banner-a3.png)

## Examples

https://zertex.ru/yii2-avatar-generator
40 changes: 40 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "zertex/avatar-generator",
"description": "Avatar generator by username, file or url.",
"version": "1.1.0",
"keywords": ["userpic", "avatar"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Egor Oldenburger",
"email": "[email protected]",
"homepage": "http://zertex.ru"
}
],
"support": {
"issues": "https://github.com/zertex/avatar-generator/issues?state=open",
"source": "https://github.com/zertex/avatar-generator"
},
"require": {
"php": ">=7.0.0",
},
"require-dev": {
"phpunit/phpunit": "4.*"
},
"autoload": {
"psr-4": {
"zertex\\avatar\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"zertex\\avatar\\tests\\": "tests/"
}
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
Loading

0 comments on commit 776e8b0

Please sign in to comment.