PHP code example of hedronium / avity

1. Go to this page and download the library: Download hedronium/avity library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hedronium / avity example snippets


use Hedronium\Avity\Avity;

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

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

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

$avity = Avity::init();

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

$avity = Avity::init();

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

$avity = Avity::init();

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

$avity = Avity::init();

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

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

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

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

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

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

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

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

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

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

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

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


use Hedronium\Avity\Generator;

/**
 * A Generator that uses php's `rand()` function.
 */
class YourRandGenerator extends Generator
{
    public function next($x, $y)
    {
        // You could use the $x & $y values to
        // return something specific but usually it souldn't matter.

        return rand();
    }
}

$avity = Avity::init([
    'generator' => YourRandGenerator::class
]);

$avity = Avity::init([
    'generator' => function () {
        return new YourRandGenerator('Please be very random.');
    }
]);


use Hedronium\Avity\Layout;

/**
 * A Generator that uses php's `rand()` function.
 */
class NoMirror extends Layout
{
    public function drawGrid(array $values)
    {
        // Sometimes, some style objects are not binary
        // they may draw more than one shape of block
        // thus the `$values` variable is passed in by the style.

        $grid = [];
        for ($y = 0; $y < $this->rows; $y++) {
            $grid[$y] = [];

            for ($x = 0; $x < $this->columns; $x++) {

                // should draw takes the `$values` and
                // returns a value based on
                // generator output

                $grid[$y][$x] = $this->shouldDraw($values);
            }
        }

        return $grid;
    }
}

$avity = Avity::init([
    'generator' => NoMirror::class
]);

$avity = Avity::init([
    'generator' => function ($generator) {
        return new NoMirror($generator, 'POTATO');
    }
]);