6
6
use Illuminate \Contracts \Cache \Repository ;
7
7
use Intervention \Image \AbstractFont ;
8
8
use Intervention \Image \AbstractShape ;
9
+ use Intervention \Image \Gd \Color ;
9
10
use Intervention \Image \ImageManager ;
10
11
use Laravolt \Avatar \Concerns \AttributeGetter ;
11
12
use Laravolt \Avatar \Concerns \AttributeSetter ;
@@ -328,8 +329,8 @@ public function buildAvatar()
328
329
329
330
$ this ->image ->text (
330
331
$ this ->initials ,
331
- $ x ,
332
- $ y ,
332
+ ( int ) $ x ,
333
+ ( int ) $ y ,
333
334
function (AbstractFont $ font ) {
334
335
$ font ->file ($ this ->font );
335
336
$ font ->size ($ this ->fontSize );
@@ -354,19 +355,61 @@ protected function createShape()
354
355
355
356
protected function createCircleShape ()
356
357
{
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
+ );
368
400
}
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
+
370
413
}
371
414
372
415
protected function createSquareShape ()
0 commit comments