Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
nemoitis committed Feb 17, 2023
1 parent 4eb6514 commit aa454b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/sowrensen/svg-avatar-generator/run-tests.yml?branch=main&label=Tests)](https://github.com/sowrensen/svg-avatar-generator/actions?query=workflow%3ATests+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/sowrensen/svg-avatar-generator.svg)](https://packagist.org/packages/sowrensen/svg-avatar-generator)


Generating SVG avatars on the fly is nothing new. There are a lot of free/paid services and packages to do that. So why
another package for same task?

Expand Down Expand Up @@ -101,6 +100,10 @@ You can define the second initial using studly case. For example,
| Johndoe | JO |
| JohndoE | JE |

## Sample Output



## Testing

Run following command to execute test cases:
Expand Down
12 changes: 7 additions & 5 deletions src/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace Sowren\SvgAvatarGenerator;

use Str;
use Sowren\SvgAvatarGenerator\Enums\Shape;

class Svg
{
/**
* Fill class name used in SVG elements.
* Gradient element ID
*/
private string $fillClassName = 'svg-fill-gradient';
private string $gradientId;

public function __construct(
public SvgAvatarGenerator $generator
) {
$this->gradientId = Str::random(32);
}

public function __toString(): string
Expand All @@ -35,7 +37,7 @@ protected function svgElement(): string
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<defs>
<linearGradient id="{$this->fillClassName}" gradientTransform="rotate({$this->generator->getGradientRotation()})">
<linearGradient id="{$this->gradientId}" gradientTransform="rotate({$this->generator->getGradientRotation()})">
<stop offset="0%" stop-color="{$this->generator->getGradientColors()[0]}"/>
<stop offset="100%" stop-color="{$this->generator->getGradientColors()[1]}"/>
</linearGradient>
Expand Down Expand Up @@ -78,14 +80,14 @@ protected function getElement(Shape $shape): string
*/
protected function circleElement(): string
{
return "<circle cx='50' cy='50' r='50' fill='url(#{$this->fillClassName})'></circle>";
return "<circle cx='50' cy='50' r='50' fill='url(#{$this->gradientId})'></circle>";
}

/**
* The rectangle element of SVG markup.
*/
protected function rectangleElement(): string
{
return "<rect width='100%' height='100%' fill='url(#{$this->fillClassName})'/>";
return "<rect width='100%' height='100%' fill='url(#{$this->gradientId})'/>";
}
}

0 comments on commit aa454b9

Please sign in to comment.