From 461aed8573e43354bf18bc768b64fd87287b6f7c Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 10 Aug 2016 15:14:50 +0200 Subject: [PATCH] added identicon library, including license, regenerated autoloader --- LICENSE.md | 27 +- vendor/composer/autoload_classmap.php | 27 +- vendor/composer/autoload_files.php | 8 - vendor/composer/autoload_namespaces.php | 7 +- vendor/composer/autoload_real.php | 18 -- vendor/composer/autoload_static.php | 39 ++- vendor/composer/installed.json | 55 +++- .../src/Identicon/Generator/BaseGenerator.php | 241 ++++++++++++++++++ .../src/Identicon/Generator/GdGenerator.php | 76 ++++++ .../Generator/GeneratorInterface.php | 33 +++ .../Generator/ImageMagickGenerator.php | 80 ++++++ .../identicon/src/Identicon/Identicon.php | 100 ++++++++ 12 files changed, 671 insertions(+), 40 deletions(-) delete mode 100644 vendor/composer/autoload_files.php create mode 100644 vendor/yzalis/identicon/src/Identicon/Generator/BaseGenerator.php create mode 100644 vendor/yzalis/identicon/src/Identicon/Generator/GdGenerator.php create mode 100644 vendor/yzalis/identicon/src/Identicon/Generator/GeneratorInterface.php create mode 100644 vendor/yzalis/identicon/src/Identicon/Generator/ImageMagickGenerator.php create mode 100644 vendor/yzalis/identicon/src/Identicon/Identicon.php diff --git a/LICENSE.md b/LICENSE.md index 2e7e76f..4d4f243 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -4,8 +4,9 @@ PrivateBin consists of PHP and JS code which was originally written by Sébastie Sauvage in 2012 and falls unter the Zlib/libpng license. Also included are libraries that fall under the GPLv2 (SJCL, rawinflate, rawdeflate), BSD 2-clause (SJCL), BSD 3-clause (base64.js version 2.1.9, Showdown), MIT -(base64.js version 1.7, Bootstrap), Apache (prettify.js) and CC-BY (favicon, -icon, logo) licenses. All of these license terms can be found here below: +(base64.js version 1.7, Bootstrap, Identicon), Apache (prettify.js) and CC-BY +(favicon, icon, logo) licenses. All of these license terms can be found here +below: ## Zlib/libpng license for PrivateBin @@ -440,6 +441,28 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +## MIT License for Identicon + +Copyright © 2013 Benjamin Laugueux + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + ## Apache License for prettify.js _Version 2.0, January 2004_ diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 5936f84..d0da43d 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -5,4 +5,29 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); -return array(); +return array( + 'Identicon\\Generator\\BaseGenerator' => $vendorDir . '/yzalis/identicon/src/Identicon/Generator/BaseGenerator.php', + 'Identicon\\Generator\\GdGenerator' => $vendorDir . '/yzalis/identicon/src/Identicon/Generator/GdGenerator.php', + 'Identicon\\Generator\\GeneratorInterface' => $vendorDir . '/yzalis/identicon/src/Identicon/Generator/GeneratorInterface.php', + 'Identicon\\Generator\\ImageMagickGenerator' => $vendorDir . '/yzalis/identicon/src/Identicon/Generator/ImageMagickGenerator.php', + 'Identicon\\Identicon' => $vendorDir . '/yzalis/identicon/src/Identicon/Identicon.php', + 'PrivateBin\\Configuration' => $baseDir . '/lib/Configuration.php', + 'PrivateBin\\Data\\AbstractData' => $baseDir . '/lib/Data/AbstractData.php', + 'PrivateBin\\Data\\Database' => $baseDir . '/lib/Data/Database.php', + 'PrivateBin\\Data\\Filesystem' => $baseDir . '/lib/Data/Filesystem.php', + 'PrivateBin\\Filter' => $baseDir . '/lib/Filter.php', + 'PrivateBin\\I18n' => $baseDir . '/lib/I18n.php', + 'PrivateBin\\Model' => $baseDir . '/lib/Model.php', + 'PrivateBin\\Model\\AbstractModel' => $baseDir . '/lib/Model/AbstractModel.php', + 'PrivateBin\\Model\\Comment' => $baseDir . '/lib/Model/Comment.php', + 'PrivateBin\\Model\\Paste' => $baseDir . '/lib/Model/Paste.php', + 'PrivateBin\\Persistence\\AbstractPersistence' => $baseDir . '/lib/Persistence/AbstractPersistence.php', + 'PrivateBin\\Persistence\\PurgeLimiter' => $baseDir . '/lib/Persistence/PurgeLimiter.php', + 'PrivateBin\\Persistence\\ServerSalt' => $baseDir . '/lib/Persistence/ServerSalt.php', + 'PrivateBin\\Persistence\\TrafficLimiter' => $baseDir . '/lib/Persistence/TrafficLimiter.php', + 'PrivateBin\\PrivateBin' => $baseDir . '/lib/PrivateBin.php', + 'PrivateBin\\Request' => $baseDir . '/lib/Request.php', + 'PrivateBin\\Sjcl' => $baseDir . '/lib/Sjcl.php', + 'PrivateBin\\View' => $baseDir . '/lib/View.php', + 'PrivateBin\\Vizhash16x16' => $baseDir . '/lib/Vizhash16x16.php', +); diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php deleted file mode 100644 index 5ca408a..0000000 --- a/vendor/composer/autoload_files.php +++ /dev/null @@ -1,8 +0,0 @@ - array($vendorDir . '/psr/log'), - 'Prophecy\\' => array($vendorDir . '/phpspec/prophecy/src'), - 'Guzzle\\Tests' => array($vendorDir . '/guzzle/guzzle/tests'), - 'Guzzle' => array($vendorDir . '/guzzle/guzzle/src'), - 'CodeClimate\\Component' => array($vendorDir . '/codeclimate/php-test-reporter/src'), - 'CodeClimate\\Bundle' => array($vendorDir . '/codeclimate/php-test-reporter/src'), + 'Identicon' => array($vendorDir . '/yzalis/identicon/src'), ); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 7ea6c55..2695ad3 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -47,24 +47,6 @@ class ComposerAutoloaderInitDontChange $loader->register(true); - if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitDontChange::$files; - } else { - $includeFiles = require __DIR__ . '/autoload_files.php'; - } - foreach ($includeFiles as $fileIdentifier => $file) { - composerRequireDontChange($fileIdentifier, $file); - } - return $loader; } } - -function composerRequireDontChange($fileIdentifier, $file) -{ - if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { - require $file; - - $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; - } -} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index bad7819..d44a987 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -6,8 +6,6 @@ namespace Composer\Autoload; class ComposerStaticInitDontChange { - public static $files = array (); - public static $prefixLengthsPsr4 = array ( 'P' => array ( @@ -22,9 +20,42 @@ class ComposerStaticInitDontChange ), ); - public static $prefixesPsr0 = array (); + public static $prefixesPsr0 = array ( + 'I' => + array ( + 'Identicon' => + array ( + 0 => __DIR__ . '/..' . '/yzalis/identicon/src', + ), + ), + ); - public static $classMap = array (); + public static $classMap = array ( + 'Identicon\\Generator\\BaseGenerator' => __DIR__ . '/..' . '/yzalis/identicon/src/Identicon/Generator/BaseGenerator.php', + 'Identicon\\Generator\\GdGenerator' => __DIR__ . '/..' . '/yzalis/identicon/src/Identicon/Generator/GdGenerator.php', + 'Identicon\\Generator\\GeneratorInterface' => __DIR__ . '/..' . '/yzalis/identicon/src/Identicon/Generator/GeneratorInterface.php', + 'Identicon\\Generator\\ImageMagickGenerator' => __DIR__ . '/..' . '/yzalis/identicon/src/Identicon/Generator/ImageMagickGenerator.php', + 'Identicon\\Identicon' => __DIR__ . '/..' . '/yzalis/identicon/src/Identicon/Identicon.php', + 'PrivateBin\\Configuration' => __DIR__ . '/../..' . '/lib/Configuration.php', + 'PrivateBin\\Data\\AbstractData' => __DIR__ . '/../..' . '/lib/Data/AbstractData.php', + 'PrivateBin\\Data\\Database' => __DIR__ . '/../..' . '/lib/Data/Database.php', + 'PrivateBin\\Data\\Filesystem' => __DIR__ . '/../..' . '/lib/Data/Filesystem.php', + 'PrivateBin\\Filter' => __DIR__ . '/../..' . '/lib/Filter.php', + 'PrivateBin\\I18n' => __DIR__ . '/../..' . '/lib/I18n.php', + 'PrivateBin\\Model' => __DIR__ . '/../..' . '/lib/Model.php', + 'PrivateBin\\Model\\AbstractModel' => __DIR__ . '/../..' . '/lib/Model/AbstractModel.php', + 'PrivateBin\\Model\\Comment' => __DIR__ . '/../..' . '/lib/Model/Comment.php', + 'PrivateBin\\Model\\Paste' => __DIR__ . '/../..' . '/lib/Model/Paste.php', + 'PrivateBin\\Persistence\\AbstractPersistence' => __DIR__ . '/../..' . '/lib/Persistence/AbstractPersistence.php', + 'PrivateBin\\Persistence\\PurgeLimiter' => __DIR__ . '/../..' . '/lib/Persistence/PurgeLimiter.php', + 'PrivateBin\\Persistence\\ServerSalt' => __DIR__ . '/../..' . '/lib/Persistence/ServerSalt.php', + 'PrivateBin\\Persistence\\TrafficLimiter' => __DIR__ . '/../..' . '/lib/Persistence/TrafficLimiter.php', + 'PrivateBin\\PrivateBin' => __DIR__ . '/../..' . '/lib/PrivateBin.php', + 'PrivateBin\\Request' => __DIR__ . '/../..' . '/lib/Request.php', + 'PrivateBin\\Sjcl' => __DIR__ . '/../..' . '/lib/Sjcl.php', + 'PrivateBin\\View' => __DIR__ . '/../..' . '/lib/View.php', + 'PrivateBin\\Vizhash16x16' => __DIR__ . '/../..' . '/lib/Vizhash16x16.php', + ); public static function getInitializer(ClassLoader $loader) { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index fe51488..5f6150d 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1 +1,54 @@ -[] +[ + { + "name": "yzalis/identicon", + "version": "1.1.0", + "version_normalized": "1.1.0.0", + "source": { + "type": "git", + "url": "https://github.com/yzalis/Identicon.git", + "reference": "a99fc2a3d018512f7914bc6f972952536c0f309b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yzalis/Identicon/zipball/a99fc2a3d018512f7914bc6f972952536c0f309b", + "reference": "a99fc2a3d018512f7914bc6f972952536c0f309b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "fzaninotto/faker": "1.2.*@dev" + }, + "time": "2014-07-13 09:19:12", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Identicon": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Benjamin Laugueux", + "email": "benjamin@yzalis.com" + } + ], + "description": "Create awesome unique avatar.", + "homepage": "http://identicon-php.org", + "keywords": [ + "avatar", + "identicon", + "image" + ] + } +] diff --git a/vendor/yzalis/identicon/src/Identicon/Generator/BaseGenerator.php b/vendor/yzalis/identicon/src/Identicon/Generator/BaseGenerator.php new file mode 100644 index 0000000..6805b1c --- /dev/null +++ b/vendor/yzalis/identicon/src/Identicon/Generator/BaseGenerator.php @@ -0,0 +1,241 @@ + + */ +class BaseGenerator +{ + /** + * @var mixed + */ + protected $generatedImage; + + /** + * @var integer + */ + protected $color; + + /** + * @var integer + */ + protected $backgroundColor; + + /** + * @var integer + */ + protected $size; + + /** + * @var integer + */ + protected $pixelRatio; + + /** + * @var string + */ + private $hash; + + /** + * @var array + */ + private $arrayOfSquare = array(); + + /** + * Set the image color + * + * @param string|array $color The color in hexa (6 chars) or rgb array + * + * @return this + */ + public function setColor($color) + { + if (null === $color) { + return $this; + } + + $this->color = $this->convertColor($color); + + return $this; + } + + /** + * Set the image background color + * + * @param string|array $backgroundColor The color in hexa (6 chars) or rgb array + * + * @return this + */ + public function setBackgroundColor($backgroundColor) + { + if (null === $backgroundColor) { + return $this; + } + + $this->backgroundColor = $this->convertColor($backgroundColor); + + return $this; + } + + private function convertColor($color) + { + $convertedColor = array(); + if (is_array($color)) { + $convertedColor[0] = $color[0]; + $convertedColor[1] = $color[1]; + $convertedColor[2] = $color[2]; + } else { + if (false !== strpos($color, '#')) { + $color = substr($color, 1); + } + $convertedColor[0] = hexdec(substr($color, 0, 2)); + $convertedColor[1] = hexdec(substr($color, 2, 2)); + $convertedColor[2] = hexdec(substr($color, 4, 2)); + } + + return $convertedColor; + } + + /** + * Get the color + * + * @return array + */ + public function getColor() + { + return $this->color; + } + + + /** + * Get the background color + * + * @return array + */ + public function getBackgroundColor() + { + return $this->backgroundColor; + } + + /** + * Convert the hash into an multidimensionnal array of boolean + * + * @return this + */ + private function convertHashToArrayOfBoolean() + { + preg_match_all('/(\w)(\w)/', $this->hash, $chars); + foreach ($chars[1] as $i => $char) { + if ($i % 3 == 0) { + $this->arrayOfSquare[$i/3][0] = $this->convertHexaToBoolean($char); + $this->arrayOfSquare[$i/3][4] = $this->convertHexaToBoolean($char); + } elseif ($i % 3 == 1) { + $this->arrayOfSquare[$i/3][1] = $this->convertHexaToBoolean($char); + $this->arrayOfSquare[$i/3][3] = $this->convertHexaToBoolean($char); + } else { + $this->arrayOfSquare[$i/3][2] = $this->convertHexaToBoolean($char); + } + ksort($this->arrayOfSquare[$i/3]); + } + + $this->color[0] = hexdec(array_pop($chars[1]))*16; + $this->color[1] = hexdec(array_pop($chars[1]))*16; + $this->color[2] = hexdec(array_pop($chars[1]))*16; + + return $this; + } + + /** + * Convert an heaxecimal number into a boolean + * + * @param string $hexa + * + * @return boolean + */ + private function convertHexaToBoolean($hexa) + { + return (bool) intval(round(hexdec($hexa)/10)); + } + + /** + * + * + * @return array + */ + public function getArrayOfSquare() + { + return $this->arrayOfSquare; + } + + /** + * Get the identicon string hash + * + * @return string + */ + public function getHash() + { + return $this->hash; + } + + /** + * Generate a hash fron the original string + * + * @param string $string + * + * @return this + */ + public function setString($string) + { + if (null === $string) { + throw new \Exception('The string cannot be null.'); + } + + $this->hash = md5($string); + + $this->convertHashToArrayOfBoolean(); + + return $this; + } + + /** + * Set the image size + * + * @param integer $size + * + * @return this + */ + public function setSize($size) + { + if (null === $size) { + return $this; + } + + $this->size = $size; + $this->pixelRatio = round($size / 5); + + return $this; + } + + /** + * Get the image size + * + * @return integer + */ + public function getSize() + { + return $this->size; + } + + /** + * Get the pixel ratio + * + * @return array + */ + public function getPixelRatio() + { + return $this->pixelRatio; + } +} diff --git a/vendor/yzalis/identicon/src/Identicon/Generator/GdGenerator.php b/vendor/yzalis/identicon/src/Identicon/Generator/GdGenerator.php new file mode 100644 index 0000000..ef7b90f --- /dev/null +++ b/vendor/yzalis/identicon/src/Identicon/Generator/GdGenerator.php @@ -0,0 +1,76 @@ + + */ +class GdGenerator extends BaseGenerator implements GeneratorInterface +{ + public function __construct() + { + if (!extension_loaded('gd')) { + throw new \Exception('GD does not appear to be avaliable in your PHP installation. Please try another generator'); + } + } + + private function generateImage() + { + // prepare image + $this->generatedImage = imagecreatetruecolor($this->getPixelRatio() * 5, $this->getPixelRatio() * 5); + + $rgbBackgroundColor = $this->getBackgroundColor(); + if (null === $rgbBackgroundColor) { + $background = imagecolorallocate($this->generatedImage, 0, 0, 0); + imagecolortransparent($this->generatedImage, $background); + } else { + $background = imagecolorallocate($this->generatedImage, $rgbBackgroundColor[0], $rgbBackgroundColor[1], $rgbBackgroundColor[2]); + imagefill($this->generatedImage, 0, 0, $background); + } + + // prepage color + $rgbColor = $this->getColor(); + $gdColor = imagecolorallocate($this->generatedImage, $rgbColor[0], $rgbColor[1], $rgbColor[2]); + + // draw content + foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) { + foreach ($lineValue as $colKey => $colValue) { + if (true === $colValue) { + imagefilledrectangle($this->generatedImage, $colKey * $this->getPixelRatio(), $lineKey * $this->getPixelRatio(), ($colKey + 1) * $this->getPixelRatio(), ($lineKey + 1) * $this->getPixelRatio(), $gdColor); + } + } + } + + return $this; + } + + /** + * {@inheritDoc} + */ + public function getImageBinaryData($string, $size = null, $color = null, $backgroundColor = null) + { + ob_start(); + imagepng($this->getImageResource($string, $size, $color, $backgroundColor)); + $imageData = ob_get_contents(); + ob_end_clean(); + + return $imageData; + } + + /** + * {@inheritDoc} + */ + public function getImageResource($string, $size = null, $color = null, $backgroundColor = null) + { + $this + ->setString($string) + ->setSize($size) + ->setColor($color) + ->setBackgroundColor($backgroundColor) + ->generateImage(); + + return $this->generatedImage; + } +} diff --git a/vendor/yzalis/identicon/src/Identicon/Generator/GeneratorInterface.php b/vendor/yzalis/identicon/src/Identicon/Generator/GeneratorInterface.php new file mode 100644 index 0000000..78be7d4 --- /dev/null +++ b/vendor/yzalis/identicon/src/Identicon/Generator/GeneratorInterface.php @@ -0,0 +1,33 @@ + + */ +interface GeneratorInterface +{ + /** + * + * + * @param string $string + * @param integer $size + * @param array|string $color + * @param array|string $backgroundColor + * + * @return mixed + */ + function getImageBinaryData($string, $size = null, $color = null, $backgroundColor = null); + + /** + * + * + * @param string $string + * @param integer $size + * @param array|string $color + * @param array|string $backgroundColor + * + * @return string + */ + function getImageResource($string, $size = null, $color = null, $backgroundColor = null); +} diff --git a/vendor/yzalis/identicon/src/Identicon/Generator/ImageMagickGenerator.php b/vendor/yzalis/identicon/src/Identicon/Generator/ImageMagickGenerator.php new file mode 100644 index 0000000..f11c51d --- /dev/null +++ b/vendor/yzalis/identicon/src/Identicon/Generator/ImageMagickGenerator.php @@ -0,0 +1,80 @@ + + */ +class ImageMagickGenerator extends BaseGenerator implements GeneratorInterface +{ + public function __construct() + { + if (!extension_loaded('imagick')) { + throw new \Exception('ImageMagick does not appear to be avaliable in your PHP installation. Please try another generator'); + } + } + + private function generateImage() + { + $this->generatedImage = new \Imagick(); + $rgbBackgroundColor = $this->getBackgroundColor(); + + if (null === $rgbBackgroundColor) { + $background = 'none'; + } else { + $background = new \ImagickPixel("rgb($rgbBackgroundColor[0],$rgbBackgroundColor[1],$rgbBackgroundColor[2])"); + } + + $this->generatedImage->newImage($this->pixelRatio * 5, $this->pixelRatio * 5, $background, 'png'); + + // prepare color + $rgbColor = $this->getColor(); + $color = new \ImagickPixel("rgb($rgbColor[0],$rgbColor[1],$rgbColor[2])"); + + $draw = new \ImagickDraw(); + $draw->setFillColor($color); + + // draw the content + foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) { + foreach ($lineValue as $colKey => $colValue) { + if (true === $colValue) { + $draw->rectangle( $colKey * $this->pixelRatio, $lineKey * $this->pixelRatio, ($colKey + 1) * $this->pixelRatio, ($lineKey + 1) * $this->pixelRatio); + } + } + } + + $this->generatedImage->drawImage($draw); + + return $this; + } + + /** + * {@inheritDoc} + */ + public function getImageBinaryData($string, $size = null, $color = null, $backgroundColor = null) + { + ob_start(); + echo $this->getImageResource($string, $size, $color, $backgroundColor); + $imageData = ob_get_contents(); + ob_end_clean(); + + return $imageData; + } + + /** + * {@inheritDoc} + */ + public function getImageResource($string, $size = null, $color = null, $backgroundColor = null) + { + $this + ->setString($string) + ->setSize($size) + ->setColor($color) + ->setBackgroundColor($backgroundColor) + ->generateImage(); + + return $this->generatedImage; + } +} diff --git a/vendor/yzalis/identicon/src/Identicon/Identicon.php b/vendor/yzalis/identicon/src/Identicon/Identicon.php new file mode 100644 index 0000000..c78ccc3 --- /dev/null +++ b/vendor/yzalis/identicon/src/Identicon/Identicon.php @@ -0,0 +1,100 @@ + + */ +class Identicon +{ + /** + * @var GeneratorInterface + */ + private $generator; + + public function __construct($generator = null) + { + if (null === $generator) { + $this->generator = new GdGenerator(); + } else { + $this->generator = $generator; + } + + } + + /** + * Set the image generetor + * + * @param GeneratorInterface $generator + * + * @throws \Exception + */ + public function setGenerator(GeneratorInterface $generator) + { + $this->generator = $generator; + + return $this; + } + + /** + * Display an Identicon image + * + * @param string $string + * @param integer $size + * @param string $color + * @param string $backgroundColor + */ + public function displayImage($string, $size = 64, $color = null, $backgroundColor = null) + { + header("Content-Type: image/png"); + echo $this->getImageData($string, $size, $color, $backgroundColor); + } + + /** + * Get an Identicon PNG image data + * + * @param string $string + * @param integer $size + * @param string $color + * @param string $backgroundColor + * + * @return string + */ + public function getImageData($string, $size = 64, $color = null, $backgroundColor = null) + { + return $this->generator->getImageBinaryData($string, $size, $color, $backgroundColor); + } + + /** + * Get an Identicon PNG image resource + * + * @param string $string + * @param integer $size + * @param string $color + * @param string $backgroundColor + * + * @return string + */ + public function getImageResource($string, $size = 64, $color = null, $backgroundColor = null) + { + return $this->generator->getImageResource($string, $size, $color, $backgroundColor); + } + + /** + * Get an Identicon PNG image data as base 64 encoded + * + * @param string $string + * @param integer $size + * @param string $color + * @param string $backgroundColor + * + * @return string + */ + public function getImageDataUri($string, $size = 64, $color = null, $backgroundColor = null) + { + return sprintf('data:image/png;base64,%s', base64_encode($this->getImageData($string, $size, $color, $backgroundColor))); + } +}