diff --git a/src/Identicon/Generator/SvgGenerator.php b/src/Identicon/Generator/SvgGenerator.php index d654a95..7e753e8 100644 --- a/src/Identicon/Generator/SvgGenerator.php +++ b/src/Identicon/Generator/SvgGenerator.php @@ -46,25 +46,28 @@ protected function _generateImage() // prepare image $w = $this->getPixelRatio() * 5; $h = $this->getPixelRatio() * 5; - $svg = ''; + $svg = ''; - $backgroundColor = '#FFFFFF'; + $backgroundColor = '#FFF'; $rgbBackgroundColor = $this->getBackgroundColor(); if (!is_null($rgbBackgroundColor)) { $backgroundColor = $this->_toUnderstandableColor($rgbBackgroundColor); } - $svg .= ''; - $rgbColor = $this->_toUnderstandableColor($this->getColor()); + $svg .= ''; + + $rects = []; // draw content foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) { foreach ($lineValue as $colKey => $colValue) { if (true === $colValue) { - $svg .= ''; + $rects[] = 'M'.$colKey.','.$lineKey.'h1v1h-1v-1'; } } } + $rgbColor = $this->_toUnderstandableColor($this->getColor()); + $svg .= ''; $svg .= ''; $this->generatedImage = $svg; @@ -80,7 +83,7 @@ protected function _generateImage() protected function _toUnderstandableColor($color) { if (is_array($color)) { - return 'rgb('.implode(', ', $color).')'; + return sprintf('#%X%X%X', $color[0], $color[1], $color[2]); } return $color; diff --git a/tests/Identicon/Tests/IdenticonTest.php b/tests/Identicon/Tests/IdenticonTest.php index c1ce0e1..85c6f39 100644 --- a/tests/Identicon/Tests/IdenticonTest.php +++ b/tests/Identicon/Tests/IdenticonTest.php @@ -3,6 +3,7 @@ namespace Identicon\Tests; use Identicon\Generator\ImageMagickGenerator; +use Identicon\Generator\SvgGenerator; use Identicon\Identicon; /** @@ -57,4 +58,28 @@ public function imageMagickResultDataProvider() ['benjaminAtYzalisDotCom', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABBAQMAAAC0OVsGAAAABlBMVEUAAABgsDAvrOz7AAAAAXRSTlMAQObYZgAAAAlwSFlzAAAASAAAAEgARslrPgAAADlJREFUKM9jYGD//4Dx/w8GIBgg1n8oaGD4/4fB/j8DP/1ZCBf8B7lqQFhQFwDDBQigIURH1oDHAgCNSlrmMVCO8AAAAABJRU5ErkJggg=='], ]; } + + /** + * @dataProvider svgResultDataProvider + */ + public function testSvgResult($string, $imageData) + { + $this->identicon->setGenerator(new SvgGenerator()); + $this->assertEquals($imageData, $this->identicon->getImageData($string)); + } + + public function svgResultDataProvider() + { + return [ + ['Benjamin', ''], + + ['8.8.8.8', ''], + + ['8.8.4.4', ''], + + ['yzalis', ''], + + ['benjaminAtYzalisDotCom', ''], + ]; + } }