@@ -11,6 +11,7 @@ class InitialAvatar
11
11
12
12
private $ parameter_cacheTime = 0 ;
13
13
private $ parameter_length = 2 ;
14
+ private $ parameter_fontSize = 0.5 ;
14
15
private $ parameter_initials = 'JD ' ;
15
16
private $ parameter_name = 'John Doe ' ;
16
17
private $ parameter_size = 48 ;
@@ -74,6 +75,13 @@ public function cache( int $minutes = 60 ): self
74
75
return $ this ;
75
76
}
76
77
78
+ public function fontSize ( float $ size = 0.5 ): self
79
+ {
80
+ $ this ->parameter_fontSize = (float ) $ size ;
81
+
82
+ return $ this ;
83
+ }
84
+
77
85
/**
78
86
* Generate the image
79
87
*
@@ -88,18 +96,19 @@ public function generate( $name = null ): Image
88
96
$ this ->parameter_initials = $ this ->generateInitials ( $ this ->parameter_name );
89
97
}
90
98
91
- $ fontFile = $ this ->parameter_fontFile ;
92
99
$ size = $ this ->parameter_size ;
93
- $ color = $ this ->parameter_fontColor ;
94
100
$ bgColor = $ this ->parameter_bgColor ;
95
101
$ name = $ this ->parameter_initials ;
102
+ $ fontFile = $ this ->parameter_fontFile ;
103
+ $ color = $ this ->parameter_fontColor ;
104
+ $ fontSize = $ this ->parameter_fontSize ;
96
105
97
- $ img = $ this ->image ->cache ( function ( ImageCache $ image ) use ( $ size , $ bgColor , $ color , $ fontFile , $ name )
106
+ $ img = $ this ->image ->cache ( function ( ImageCache $ image ) use ( $ size , $ bgColor , $ color , $ fontFile , $ name, $ fontSize )
98
107
{
99
- $ image ->canvas ( $ size , $ size , $ bgColor )->text ( $ name , $ size / 2 , $ size / 2 , function ( $ font ) use ( $ size , $ color , $ fontFile )
108
+ $ image ->canvas ( $ size , $ size , $ bgColor )->text ( $ name , $ size / 2 , $ size / 2 , function ( $ font ) use ( $ size , $ color , $ fontFile, $ fontSize )
100
109
{
101
110
$ font ->file ( __DIR__ . $ fontFile );
102
- $ font ->size ( $ size / 2 );
111
+ $ font ->size ( $ size * $ fontSize );
103
112
$ font ->color ( $ color );
104
113
$ font ->align ( 'center ' );
105
114
$ font ->valign ( 'center ' );
0 commit comments