PHPackages                             hedronium/avity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. hedronium/avity

ActiveLibrary[Image &amp; Media](/categories/media)

hedronium/avity
===============

Highly extensible &amp; customizable Identicon Generator

v1.0(10y ago)12871[1 PRs](https://github.com/Hedronium/Avity/pulls)MITPHPCI failing

Since Nov 27Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Hedronium/Avity)[ Packagist](https://packagist.org/packages/hedronium/avity)[ RSS](/packages/hedronium-avity/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Avity
=====

[](#avity)

---

[![Logo](https://camo.githubusercontent.com/e7b2ff39ac56e018dc58b95b8ca262e845a0f5f67c6df2ca60610a16f5f924ce/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7661726965645f312e6a706567)](https://camo.githubusercontent.com/e7b2ff39ac56e018dc58b95b8ca262e845a0f5f67c6df2ca60610a16f5f924ce/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7661726965645f312e6a706567)

Highly Customizable Identicon Generator for PHP.

Installation
============

[](#installation)

Get it through composer cli.

```
composer require hedronium/avity

```

Getting Started
===============

[](#getting-started)

```
use Hedronium\Avity\Avity;

$avity = Avity::init()->generate()->jpg()->toBrowser();
```

Thats it thats all you really need to generate an Identicon. The above code will generate an Identicon based on Random values.

Basic Customization
===================

[](#basic-customization)

Customizing Image Dimensions
----------------------------

[](#customizing-image-dimensions)

You can call the `height($value)` and `width($value)` method on the `Avity` instance after initialization. Like:

```
$avity = Avity::init();
$avity->height(600)->width(500); // Long Vertical Identicon. WOW!

$avity->generate()->jpg()->toBrowser();
```

Yes, its a Fluent API, method chaining is cool!

Customizing Background &amp; Foreground Color
---------------------------------------------

[](#customizing-background--foreground-color)

```
$avity = Avity::init();

$avity->style()->background(20, 20, 40)
->foreground(100, 240, 255);
```

Both the methods accept `$r, $g, $b` parameters.

[![Dark](https://camo.githubusercontent.com/f263404d7eec299abf6f195f8a060128f1ae02752626307a889ddaa4f1fc48b3/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f6461726b2e6a706567)](https://camo.githubusercontent.com/f263404d7eec299abf6f195f8a060128f1ae02752626307a889ddaa4f1fc48b3/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f6461726b2e6a706567)

Customizing the Grid
--------------------

[](#customizing-the-grid)

```
$avity = Avity::init();

$avity->rows(3)->columns(3); // 3x3 Grid
```

[![3 by 3](https://camo.githubusercontent.com/17856578d414f94e03347b67711f252cac4115351d200f39ed0cf90067626248/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f335f62795f332e6a706567)](https://camo.githubusercontent.com/17856578d414f94e03347b67711f252cac4115351d200f39ed0cf90067626248/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f335f62795f332e6a706567)

Padding
-------

[](#padding)

[![Padding](https://camo.githubusercontent.com/58db8bb65aa03e892029a754d42e4f9f1a20fbf32e80d735d29fa085d6898f7a/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7061646465642e6a706567)](https://camo.githubusercontent.com/58db8bb65aa03e892029a754d42e4f9f1a20fbf32e80d735d29fa085d6898f7a/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7061646465642e6a706567)

```
$avity = Avity::init();

$avity->padding(100); //100px padding
```

Style Specific Customizations.
------------------------------

[](#style-specific-customizations)

Often the style class used has specific methods that customize its behaviour which are not directly available on the Avity object for such cases the style instance can be fetched with the `style()` method on the `Avity` instance.

Like:

```
$avity = Avity::init();

$avity->style()->variedColor()->spacing(10); // `spacing()` & `variedColor()` is a style specific method
```

[![Varied Color](https://camo.githubusercontent.com/6889d03bb73e12637a077c54535b05762842e4bb881152704f4da4a225f2e20e/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7661726965645f322e6a706567)](https://camo.githubusercontent.com/6889d03bb73e12637a077c54535b05762842e4bb881152704f4da4a225f2e20e/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7661726965645f322e6a706567)[![Varied Color](https://camo.githubusercontent.com/e7b2ff39ac56e018dc58b95b8ca262e845a0f5f67c6df2ca60610a16f5f924ce/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7661726965645f312e6a706567)](https://camo.githubusercontent.com/e7b2ff39ac56e018dc58b95b8ca262e845a0f5f67c6df2ca60610a16f5f924ce/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7661726965645f312e6a706567)

Controlling the Output
======================

[](#controlling-the-output)

Output Format
-------------

[](#output-format)

Avity can output as `jpg`, `png` or `gif`

```
Avity::init()->generate()->jpg()->toBrowser();
Avity::init()->generate()->png()->toBrowser();
Avity::init()->generate()->gif()->toBrowser();
```

Output Quality
--------------

[](#output-quality)

The quality of the generated image may also be set. Give it a number between 1 and 100. (Only aplicable for `jpg` &amp; `png`)

```
Avity::init()->generate()->jpg()->quality(80)->toBrowser();
```

Output To Browser
-----------------

[](#output-to-browser)

```
Avity::init()->generate()->jpg()->toBrowser();
```

Output To File
--------------

[](#output-to-file)

```
Avity::init()->generate()->jpg()->toFile('/server/potato.jpg');
```

Generators
==========

[](#generators)

`Generators` are objects that generate numbers. These numbers are used by Layouts to set blocks onto the grid.

To use a different generator you can pass in an associative array of options with the `generator` key and the class bane as the value. Like:

```
$avity = Avity::init([
    'generator' => \Hedronium\Avity\Generators\Hash::class
]);
```

available classes:

- `\Hedronium\Avity\Generators\Hash` (*default*)
- `\Hedronium\Avity\Generators\Random`

The Hash Generator
------------------

[](#the-hash-generator)

Once you got the generator setup like above to pass in a value to hash you can call `hash()` on the `Avity` instance. (it can be anything, like the user's username or email address or id)

```
$avity = Avity::init([
    'generator' => \Hedronium\Avity\Generators\Hash::class
]);

$avity->hash('I like Bananas.'); // I really like bananas
```

This will generate the same identicon each time you give it the same value to hash.

Layouts
=======

[](#layouts)

`Layout` objects use `Generator` objects to set blocks onto the grid. Avity comes with 3 built in `Layout` classes:

- `\Hedronium\Avity\Layouts\VerticalMirror` (*default*)
- `\Hedronium\Avity\Layouts\HorizontalMirror`
- `\Hedronium\Avity\Layouts\DiagonalMirror`

[![Avity](https://camo.githubusercontent.com/0a4067ff0a0b44d25dc5bf20c76354a5a92657cb1d9f2931686b50c5ceda407d/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f766572746963616c5f6d6972726f722e6a706567)](https://camo.githubusercontent.com/0a4067ff0a0b44d25dc5bf20c76354a5a92657cb1d9f2931686b50c5ceda407d/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f766572746963616c5f6d6972726f722e6a706567)[![Avity](https://camo.githubusercontent.com/1b08613b8726e453e6b7b21fdc98530fbc49574f5028643fb5332439f9e9928f/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f686f72697a6f6e74616c5f6d6972726f722e6a706567)](https://camo.githubusercontent.com/1b08613b8726e453e6b7b21fdc98530fbc49574f5028643fb5332439f9e9928f/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f686f72697a6f6e74616c5f6d6972726f722e6a706567)

changing the layout class

```
$avity = Avity::init([
    'layout' => \Hedronium\Avity\Layouts\DiagonalMirror::class
]);
```

Styles
======

[](#styles)

`Style` objects use `Layout` objects to draw the grid onto a canvas. Avity comes with 4 built in `Style` classes:

- `\Hedronium\Avity\Styles\Square` (*default*)
- `\Hedronium\Avity\Styles\SquareCircle`
- `\Hedronium\Avity\Styles\Circle`
- `\Hedronium\Avity\Styles\Triangle`

[![Avity](https://camo.githubusercontent.com/0a4067ff0a0b44d25dc5bf20c76354a5a92657cb1d9f2931686b50c5ceda407d/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f766572746963616c5f6d6972726f722e6a706567)](https://camo.githubusercontent.com/0a4067ff0a0b44d25dc5bf20c76354a5a92657cb1d9f2931686b50c5ceda407d/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f766572746963616c5f6d6972726f722e6a706567)[![Avity](https://camo.githubusercontent.com/b9ec4a2f8189c8ce47fb49a282467184221f61c3c7c74d87e82454ee81e02696/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f636972636c652e6a706567)](https://camo.githubusercontent.com/b9ec4a2f8189c8ce47fb49a282467184221f61c3c7c74d87e82454ee81e02696/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f636972636c652e6a706567)

changing the style class

```
$avity = Avity::init([
    'layout' => \Hedronium\Avity\Styles\Triangle::class
]);
```

spacing()
---------

[](#spacing)

[![Avity](https://camo.githubusercontent.com/982f2310b46c162ef790e868b34644a98d55f0db0d151bd7fa70fc353a1f4997/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7370616365642e6a706567)](https://camo.githubusercontent.com/982f2310b46c162ef790e868b34644a98d55f0db0d151bd7fa70fc353a1f4997/687474703a2f2f686564726f6e69756d2e6769746875622e696f2f41766974792f696d616765732f7370616365642e6a706567)

All built in `Style` classes have a `spacing(_int_ $value)` method that can be used to set the space between blocks. Like:

```
$avity = Avity::init();
$avity->style()->spacing(30);
```

variedColor()
-------------

[](#variedcolor)

This ones a fun method available to all default `Style` classes. Just call it and see the magic happen. Like:

```
$avity = Avity::init();
$avity->style()->variedColor();
```

Advanced Customization
======================

[](#advanced-customization)

Custom Generator
----------------

[](#custom-generator)

A generator class should always extend `Hedronium\Avity\Generator`example:

```
