Skip to content

Commit c503539

Browse files
committed
wip: support for php 8.1
1 parent 09f8bb8 commit c503539

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
],
2020
"require": {
2121
"php": ">=7.3",
22-
"illuminate/support": "^6.0|^7.0|^8.0|^9.0",
23-
"illuminate/cache": "^6.0|^7.0|^8.0|^9.0",
24-
"intervention/image": "^2.5"
22+
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
23+
"illuminate/cache": "^6.0|^7.0|^8.0|^9.0|^10.0",
24+
"intervention/image": "^2.7"
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "~9.0",

src/Avatar.php

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Contracts\Cache\Repository;
77
use Intervention\Image\AbstractFont;
88
use Intervention\Image\AbstractShape;
9+
use Intervention\Image\Gd\Color;
910
use Intervention\Image\ImageManager;
1011
use Laravolt\Avatar\Concerns\AttributeGetter;
1112
use Laravolt\Avatar\Concerns\AttributeSetter;
@@ -328,8 +329,8 @@ public function buildAvatar()
328329

329330
$this->image->text(
330331
$this->initials,
331-
$x,
332-
$y,
332+
(int) $x,
333+
(int) $y,
333334
function (AbstractFont $font) {
334335
$font->file($this->font);
335336
$font->size($this->fontSize);
@@ -354,19 +355,61 @@ protected function createShape()
354355

355356
protected function createCircleShape()
356357
{
357-
$circleDiameter = $this->width - $this->borderSize;
358-
$x = $this->width / 2;
359-
$y = $this->height / 2;
360-
361-
$this->image->circle(
362-
$circleDiameter,
363-
$x,
364-
$y,
365-
function (AbstractShape $draw) {
366-
$draw->background($this->background);
367-
$draw->border($this->borderSize, $this->getBorderColor());
358+
$circleDiameter = (int) ($this->width - $this->borderSize);
359+
$x = (int) ($this->width / 2);
360+
$y = (int) ($this->height / 2);
361+
362+
if ($this->driver === 'gd') {
363+
// parse background color
364+
$background = new Color($this->background);
365+
366+
if ($this->borderSize) {
367+
// slightly smaller ellipse to keep 1px bordered edges clean
368+
imagefilledellipse(
369+
$this->image->getCore(),
370+
$x,
371+
$y,
372+
$this->width - 1,
373+
$this->height - 1,
374+
$background->getInt()
375+
);
376+
377+
$border_color = new Color($this->getBorderColor());
378+
imagesetthickness($this->image->getCore(), $this->borderSize);
379+
380+
// gd's imageellipse doesn't respect imagesetthickness so i use imagearc with 359.9 degrees here
381+
imagearc(
382+
$this->image->getCore(),
383+
$x,
384+
$y,
385+
$circleDiameter,
386+
$circleDiameter,
387+
0,
388+
(int) 359.99,
389+
$border_color->getInt()
390+
);
391+
} else {
392+
imagefilledellipse(
393+
$this->image->getCore(),
394+
$x,
395+
$y,
396+
$circleDiameter,
397+
$circleDiameter,
398+
$background->getInt()
399+
);
368400
}
369-
);
401+
} else {
402+
$this->image->circle(
403+
$circleDiameter,
404+
$x,
405+
$y,
406+
function (AbstractShape $draw) {
407+
// $draw->background($this->background);
408+
$draw->border($this->borderSize, $this->getBorderColor());
409+
}
410+
);
411+
}
412+
370413
}
371414

372415
protected function createSquareShape()

src/Generator/DefaultGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function make($name, $length = 2, $uppercase = false, $ascii = false, $rt
1313
{
1414
$this->setName($name, $ascii);
1515

16-
$words = new Collection(explode(' ', $this->name));
16+
$words = new Collection(explode(' ', (string)$this->name));
1717

1818
// if name contains single word, use first N character
1919
if ($words->count() === 1) {
@@ -61,7 +61,7 @@ protected function getInitialFromOneWord($words, $length)
6161
{
6262
$initial = (string)$words->first();
6363

64-
if (strlen($this->name) >= $length) {
64+
if (strlen((string)$this->name) >= $length) {
6565
$initial = Str::substr($this->name, 0, $length);
6666
}
6767

0 commit comments

Comments
 (0)