@@ -99,6 +99,26 @@ class User extends Element implements IdentityInterface
99
99
100
100
public const IMPERSONATE_KEY = 'Craft.UserSessionService.prevImpersonateUserId ' ;
101
101
102
+ private static array $ photoColors = [
103
+ 'red-100 ' ,
104
+ 'orange-200 ' ,
105
+ 'amber-200 ' ,
106
+ 'yellow-200 ' ,
107
+ 'lime-200 ' ,
108
+ 'green-200 ' ,
109
+ 'emerald-200 ' ,
110
+ 'teal-200 ' ,
111
+ 'cyan-200 ' ,
112
+ 'sky-200 ' ,
113
+ 'blue-200 ' ,
114
+ 'indigo-200 ' ,
115
+ 'violet-200 ' ,
116
+ 'purple-200 ' ,
117
+ 'fuchsia-200 ' ,
118
+ 'pink-100 ' ,
119
+ 'rose-200 ' ,
120
+ ];
121
+
102
122
// User statuses
103
123
// -------------------------------------------------------------------------
104
124
@@ -1266,7 +1286,46 @@ public function getThumbUrl(int $size): ?string
1266
1286
*/
1267
1287
protected function thumbSvg (): ?string
1268
1288
{
1269
- return file_get_contents (Craft::getAlias ('@appicons/user.svg ' ));
1289
+ $ name = $ this ->getName ();
1290
+ $ words = StringHelper::splitOnWords ($ name );
1291
+ if (count ($ words ) > 2 ) {
1292
+ $ words = [$ words [0 ], end ($ words )];
1293
+ }
1294
+ $ initials = implode ('' , array_map (fn ($ word ) => mb_strtoupper (mb_substr ($ word , 0 , 1 )), $ words ));
1295
+
1296
+ // Choose a color based on the UUID
1297
+ $ uid = strtolower ($ this ->uid ?? '00ff ' );
1298
+ $ color1Index = (int )base_convert (substr ($ uid , 0 , 2 ), 16 , 10 );
1299
+ $ color2Index = (int )base_convert (substr ($ uid , -2 ), 16 , 10 );
1300
+ if ($ color2Index >= $ color1Index - 1 && $ color2Index <= $ color1Index + 1 ) {
1301
+ $ color2Index = $ color1Index + 2 ;
1302
+ }
1303
+ $ totalColors = count (self ::$ photoColors );
1304
+ $ color1 = self ::$ photoColors [$ color1Index % $ totalColors ];
1305
+ $ color2 = self ::$ photoColors [$ color2Index % $ totalColors ];
1306
+
1307
+ $ gradientId = sprintf ('gradient-%s ' , StringHelper::randomString (10 ));
1308
+
1309
+ return <<<XML
1310
+ <svg version="1.1" baseProfile="full" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
1311
+ <defs>
1312
+ <linearGradient id=" $ gradientId" x1="0" y1="1" x2="1" y2="0">
1313
+ <stop class="stop1" offset="0%" />
1314
+ <stop class="stop2" offset="100%" />
1315
+ </linearGradient>
1316
+ </defs>
1317
+ <style>
1318
+ <![CDATA[
1319
+ .stop1 { stop-color: var(-- $ color1); }
1320
+ .stop2 { stop-color: var(-- $ color2); }
1321
+ ]]>
1322
+ </style>
1323
+ </defs>
1324
+ <circle cx="50" cy="50" r="50" fill="url(# $ gradientId)"/>
1325
+ <text x="50" y="69" font-size="46" font-family="sans-serif" text-anchor="middle" fill="var(--white)" fill-opacity="0.4"> $ initials</text>
1326
+ <text x="50" y="66" font-size="46" font-family="sans-serif" text-anchor="middle" fill="var(--black)" fill-opacity="0.65"> $ initials</text>
1327
+ </svg>
1328
+ XML ;
1270
1329
}
1271
1330
1272
1331
/**
0 commit comments