Skip to content

Commit

Permalink
Merge 5d6da31 into bec4686
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-mackie committed Feb 29, 2020
2 parents bec4686 + 5d6da31 commit d930b93
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
'color' => 'background',
],

// SVG Border Radius
'borderRadius' => 0,

// List of theme name to be used when rendering avatar
// Possible values are:
// 1. Theme name as string: 'colorful'
Expand Down
5 changes: 5 additions & 0 deletions src/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Avatar

protected $borderColor;

protected $borderRadius = 0;

protected $ascii = false;

protected $uppercase = false;
Expand Down Expand Up @@ -131,6 +133,7 @@ public function applyTheme(array $config)
$this->uppercase = $config['uppercase'];
$this->borderSize = $config['border']['size'];
$this->borderColor = $config['border']['color'];
$this->borderRadius = $config['borderRadius'];
}

public function addTheme(string $name, array $config)
Expand Down Expand Up @@ -209,6 +212,7 @@ public function toSvg()
.'" width="'.$width.'" height="'.$height
.'" stroke="'.$this->borderColor
.'" stroke-width="'.$this->borderSize
.'" rx="'.$this->borderRadius
.'" fill="'.$this->background.'" />';
} elseif ($this->shape == 'circle') {
$svg .= '<circle cx="'.$center
Expand Down Expand Up @@ -450,6 +454,7 @@ protected function validateConfig($config)
'size' => 1,
'color' => 'foreground',
],
'borderRadius' => 0
];

return $config + $this->defaultTheme + $fallback;
Expand Down
7 changes: 7 additions & 0 deletions src/Concerns/AttributeSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public function setBorder($size, $color)
return $this;
}

public function setBorderRadius($radius)
{
$this->borderRadius = $radius;

return $this;
}

public function setShape($shape)
{
$this->shape = $shape;
Expand Down
2 changes: 2 additions & 0 deletions tests/AvatarLaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function it_can_override_attributes_when_instantiated()
'foregrounds' => ['#FFFFFF'],
'backgrounds' => ['#000000'],
'border' => ['size' => 1, 'color' => '#999999'],
'borderRadius'=> 15,
];

$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');
Expand All @@ -39,6 +40,7 @@ public function it_can_override_attributes_when_instantiated()
$this->assertAttributeEquals(48, 'fontSize', $avatar);
$this->assertAttributeEquals(1, 'borderSize', $avatar);
$this->assertAttributeEquals('#999999', 'borderColor', $avatar);
$this->assertAttributeEquals(15, 'borderRadius', $avatar);
$this->assertAttributeEquals(false, 'ascii', $avatar);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/AvatarPhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function it_can_override_attributes_when_instantiated()
'foregrounds' => ['#FFFFFF'],
'backgrounds' => ['#000000'],
'border' => ['size' => 1, 'color' => '#999999'],
'borderRadius'=> 15,
];

$avatar = new \Laravolt\Avatar\Avatar($config);
Expand All @@ -32,6 +33,7 @@ public function it_can_override_attributes_when_instantiated()
$this->assertAttributeEquals(48, 'fontSize', $avatar);
$this->assertAttributeEquals(1, 'borderSize', $avatar);
$this->assertAttributeEquals('#999999', 'borderColor', $avatar);
$this->assertAttributeEquals(15, 'borderRadius', $avatar);
$this->assertAttributeEquals(false, 'ascii', $avatar);
}

Expand Down Expand Up @@ -198,7 +200,7 @@ public function it_can_generate_circle_svg()
public function it_can_generate_rectangle_svg()
{
$expected = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">';
$expected .= '<rect x="5" y="5" width="90" height="90" stroke="yellow" stroke-width="10" fill="red" />';
$expected .= '<rect x="5" y="5" width="90" height="90" stroke="yellow" stroke-width="10" rx="15" fill="red" />';
$expected .= '<text x="50" y="50" font-size="24" fill="white" alignment-baseline="middle" text-anchor="middle" dominant-baseline="central">AB</text>';
$expected .= '</svg>';

Expand All @@ -209,6 +211,7 @@ public function it_can_generate_rectangle_svg()
->setDimension(100, 100)
->setForeground('white')
->setBorder(10, 'yellow')
->setBorderRadius(15)
->setBackground('red')
->toSvg();

Expand Down

0 comments on commit d930b93

Please sign in to comment.