PHP code example of usarise / identicon

1. Go to this page and download the library: Download usarise/identicon 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/ */

    

usarise / identicon example snippets




declare(strict_types=1);

;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

$identicon = new Identicon(
    new SvgCanvas(),
    420,
);

$response = $identicon->generate('test');

header("Content-type: {$response->mimeType}");
echo (string) $response;



declare(strict_types=1);

;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

$identicon = new Identicon(
    new SvgCanvas(),
    420,
);

$response = $identicon->generate('test');
$response->save("test.{$response->format}");



declare(strict_types=1);

;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

$identicon = new Identicon(
    new SvgCanvas(),
    420,
);

$response = $identicon->generate('test');
$data = sprintf(
    'data:%s;base64,%s',
    $response->mimeType,
    base64_encode(
        (string) $response,
    ),
);

use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;
use Usarise\Identicon\{Identicon, Resolution};

$identicon = new Identicon(
    image: new SvgCanvas(), // implementation Usarise\Identicon\Image\CanvasInterface
    size: 420, // 420x420 pixels
    resolution: Resolution::Medium, // Resolution 10x10 (Default)
);

use Usarise\Identicon\Image\Gd\Canvas as GdCanvas;
use Usarise\Identicon\Image\Imagick\Canvas as ImagickCanvas;
use Usarise\Identicon\Image\Svg\Canvas as SvgCanvas;

new GdCanvas()

new ImagickCanvas()

new SvgCanvas()

use Usarise\Identicon\Resolution;

Resolution::Tiny

Resolution::Small

Resolution::Medium

Resolution::Large

Resolution::Huge

$response = $identicon->generate(string: 'test')

$response = $identicon->generate(string: 'test', background: '#f2f1f2')

$response = $identicon->generate(string: 'test', foreground: '#84c7b5')

$response = $identicon->generate(string: 'test', background: '#f2f1f2', foreground: '#84c7b5')

$response->format // svg

$response->mimeType // image/svg+xml

$response->output

(string) $response

$response->image // object

$response->save(path: __DIR__ . '/test.svg')