Skip to content

Commit 817823d

Browse files
committed
allowSpecialCharacters
1 parent 3f57081 commit 817823d

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

src/InitialAvatar.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@ class InitialAvatar
2424
/** @var Initials */
2525
protected $initials_generator;
2626

27-
protected $driver = 'gd'; // imagick or gd
28-
protected $fontSize = 0.5;
29-
protected $name = 'John Doe';
30-
protected $width = 48;
31-
protected $height = 48;
32-
protected $bgColor = '#f0e9e9';
33-
protected $fontColor = '#8b5d5d';
34-
protected $rounded = false;
35-
protected $smooth = false;
36-
protected $autofont = false;
37-
protected $keepCase = false;
38-
protected $fontFile = '/fonts/OpenSans-Regular.ttf';
39-
protected $fontName = 'OpenSans, sans-serif';
40-
protected $generated_initials = 'JD';
41-
protected $preferBold = false;
27+
protected $driver = 'gd'; // imagick or gd
28+
protected $fontSize = 0.5;
29+
protected $name = 'John Doe';
30+
protected $width = 48;
31+
protected $height = 48;
32+
protected $bgColor = '#f0e9e9';
33+
protected $fontColor = '#8b5d5d';
34+
protected $rounded = false;
35+
protected $smooth = false;
36+
protected $autofont = false;
37+
protected $keepCase = false;
38+
protected $allowSpecialCharacters = true;
39+
protected $fontFile = '/fonts/OpenSans-Regular.ttf';
40+
protected $fontName = 'OpenSans, sans-serif';
41+
protected $generated_initials = 'JD';
42+
protected $preferBold = false;
4243

4344
/**
4445
* Language eg.en zh-CN
@@ -313,6 +314,19 @@ public function keepCase( $keepCase = true ) {
313314
return $this;
314315
}
315316

317+
/**
318+
* Set if should allow (or remove) special characters
319+
*
320+
* @param bool $allowSpecialCharacters
321+
*
322+
* @return $this
323+
*/
324+
public function allowSpecialCharacters( $allowSpecialCharacters = true ) {
325+
$this->allowSpecialCharacters = (bool) $allowSpecialCharacters;
326+
327+
return $this;
328+
}
329+
316330
/**
317331
* Set the font size in percentage
318332
* (0.1 = 10%).
@@ -337,7 +351,9 @@ public function fontSize( $size = 0.5 ) {
337351
public function generate( $name = null ) {
338352
if ( $name !== null ) {
339353
$this->name = $name;
340-
$this->generated_initials = $this->initials_generator->keepCase( $this->getKeepCase() )->generate( $name );
354+
$this->generated_initials = $this->initials_generator->keepCase( $this->getKeepCase() )
355+
->allowSpecialCharacters( $this->getAllowSpecialCharacters() )
356+
->generate( $name );
341357
}
342358

343359
return $this->makeAvatar( $this->image );
@@ -474,6 +490,15 @@ public function getKeepCase() {
474490
return $this->keepCase;
475491
}
476492

493+
/**
494+
* Will return the allowSpecialCharacters parameter.
495+
*
496+
* @return boolean
497+
*/
498+
public function getAllowSpecialCharacters() {
499+
return $this->allowSpecialCharacters;
500+
}
501+
477502
/**
478503
* Will return the autofont parameter.
479504
*

0 commit comments

Comments
 (0)