@@ -42,21 +42,21 @@ class InitialAvatar
4242 protected $ preferBold = false ;
4343
4444 /**
45- * Language eg.en zh-CN
45+ * Language eg.en zh-CN.
4646 *
4747 * @var string
4848 */
4949 protected $ language = 'en ' ;
5050
5151 /**
52- * Role translator
52+ * Role translator.
5353 *
5454 * @var Base
5555 */
5656 protected $ translator ;
5757
5858 /**
59- * Language related to translator
59+ * Language related to translator.
6060 *
6161 * @var array
6262 */
@@ -72,7 +72,7 @@ public function __construct()
7272 }
7373
7474 /**
75- * Create a ImageManager instance
75+ * Create a ImageManager instance.
7676 */
7777 protected function setupImageManager ()
7878 {
@@ -89,14 +89,14 @@ protected function setupImageManager()
8989 public function name ($ nameOrInitials )
9090 {
9191 $ nameOrInitials = $ this ->translate ($ nameOrInitials );
92- $ this ->name = $ nameOrInitials ;
92+ $ this ->name = $ nameOrInitials ;
9393 $ this ->initials_generator ->name ($ nameOrInitials );
9494
9595 return $ this ;
9696 }
9797
9898 /**
99- * Transforms a unicode string to the proper format
99+ * Transforms a unicode string to the proper format.
100100 *
101101 * @param string $char the code to be converted (e.g., f007 would mean the "user" symbol)
102102 *
@@ -133,7 +133,7 @@ public function length($length = 2)
133133 */
134134 public function size ($ size )
135135 {
136- $ this ->width = (int ) $ size ;
136+ $ this ->width = (int ) $ size ;
137137 $ this ->height = (int ) $ size ;
138138
139139 return $ this ;
@@ -168,7 +168,7 @@ public function width($width)
168168 }
169169
170170 /**
171- * Prefer bold fonts (if possible)
171+ * Prefer bold fonts (if possible).
172172 *
173173 * @return $this
174174 */
@@ -180,7 +180,7 @@ public function preferBold()
180180 }
181181
182182 /**
183- * Prefer regular fonts (if possible)
183+ * Prefer regular fonts (if possible).
184184 *
185185 * @return $this
186186 */
@@ -220,16 +220,15 @@ public function color($color)
220220 }
221221
222222 /**
223- * Automatically set a font and/or background color based on the supplied name
224- *
223+ * Automatically set a font and/or background color based on the supplied name.
224+ *
225225 * @param bool $foreground
226226 * @param bool $background
227- *
227+ *
228228 * @return $this
229229 */
230230 public function autoColor (bool $ foreground = true , bool $ background = true , int $ saturation = 85 , int $ luminance = 60 )
231231 {
232-
233232 $ hue = (crc32 ($ this ->name ) % 360 ) / 360 ;
234233 $ saturation /= 100 ;
235234 $ luminance /= 100 ;
@@ -255,7 +254,7 @@ public function font($font)
255254 }
256255
257256 /**
258- * Set the font name
257+ * Set the font name.
259258 *
260259 * Example: "Open Sans"
261260 *
@@ -356,7 +355,7 @@ public function keepCase($keepCase = true)
356355 }
357356
358357 /**
359- * Set if should allow (or remove) special characters
358+ * Set if should allow (or remove) special characters.
360359 *
361360 * @param bool $allowSpecialCharacters
362361 *
@@ -394,7 +393,7 @@ public function fontSize($size = 0.5)
394393 public function generate ($ name = null )
395394 {
396395 if ($ name !== null ) {
397- $ this ->name = $ name ;
396+ $ this ->name = $ name ;
398397 $ this ->generated_initials = $ this ->initials_generator ->keepCase ($ this ->getKeepCase ())
399398 ->allowSpecialCharacters ($ this ->getAllowSpecialCharacters ())
400399 ->generate ($ name );
@@ -413,7 +412,7 @@ public function generate($name = null)
413412 public function generateSvg ($ name = null )
414413 {
415414 if ($ name !== null ) {
416- $ this ->name = $ name ;
415+ $ this ->name = $ name ;
417416 $ this ->generated_initials = $ this ->initials_generator ->keepCase ($ this ->getKeepCase ())
418417 ->allowSpecialCharacters ($ this ->getAllowSpecialCharacters ())
419418 ->generate ($ name );
@@ -546,7 +545,7 @@ public function getHeight()
546545 /**
547546 * Will return the keepCase parameter.
548547 *
549- * @return boolean
548+ * @return bool
550549 */
551550 public function getKeepCase ()
552551 {
@@ -556,7 +555,7 @@ public function getKeepCase()
556555 /**
557556 * Will return the allowSpecialCharacters parameter.
558557 *
559- * @return boolean
558+ * @return bool
560559 */
561560 public function getAllowSpecialCharacters ()
562561 {
@@ -578,7 +577,7 @@ public function getAutoFont()
578577 * ```php
579578 * $avatar->language('en')->name('Mr Green'); // Right
580579 * $avatar->name('Mr Green')->language('en'); // Wrong
581- * ```
580+ * ```.
582581 *
583582 * @param string $language
584583 *
@@ -592,15 +591,15 @@ public function language($language)
592591 }
593592
594593 /**
595- * Add new translators designed by user
594+ * Add new translators designed by user..
596595 *
597596 * @param array $translatorMap
598- * ```php
599- * $translatorMap = [
600- * 'fr' => 'foo\bar\Fr',
601- * 'zh-TW' => 'foo\bar\ZhTW'
602- * ];
603- * ```
597+ * ```php
598+ * $translatorMap = [
599+ * 'fr' => 'foo\bar\Fr',
600+ * 'zh-TW' => 'foo\bar\ZhTW'
601+ * ];
602+ * ```
604603 *
605604 * @return $this
606605 */
@@ -611,16 +610,13 @@ public function addTranslators($translatorMap)
611610 return $ this ;
612611 }
613612
614- /**
615- * @inheritdoc
616- */
617613 protected function translate ($ nameOrInitials )
618614 {
619615 return $ this ->getTranslator ()->translate ($ nameOrInitials );
620616 }
621617
622618 /**
623- * Instance the translator by language
619+ * Instance the translator by language.
624620 *
625621 * @return Base
626622 */
@@ -642,12 +638,12 @@ protected function getTranslator()
642638 */
643639 protected function makeAvatar ($ image )
644640 {
645- $ width = $ this ->getWidth ();
646- $ height = $ this ->getHeight ();
647- $ bgColor = $ this ->getBackgroundColor ();
648- $ name = $ this ->getInitials ();
641+ $ width = $ this ->getWidth ();
642+ $ height = $ this ->getHeight ();
643+ $ bgColor = $ this ->getBackgroundColor ();
644+ $ name = $ this ->getInitials ();
649645 $ fontFile = $ this ->findFontFile ();
650- $ color = $ this ->getColor ();
646+ $ color = $ this ->getColor ();
651647 $ fontSize = $ this ->getFontSize ();
652648
653649 if ($ this ->getRounded () && $ this ->getSmooth ()) {
@@ -684,7 +680,7 @@ protected function makeAvatar($image)
684680 protected function makeSvgAvatar ()
685681 {
686682 // Original document
687- $ image = new SVG ($ this ->getWidth (), $ this ->getHeight ());
683+ $ image = new SVG ($ this ->getWidth (), $ this ->getHeight ());
688684 $ document = $ image ->getDocument ();
689685
690686 // Background
@@ -745,12 +741,12 @@ protected function findFontFile()
745741 return $ fontFile ;
746742 }
747743
748- if (file_exists (__DIR__ . $ fontFile )) {
749- return __DIR__ . $ fontFile ;
744+ if (file_exists (__DIR__ . $ fontFile )) {
745+ return __DIR__ . $ fontFile ;
750746 }
751747
752- if (file_exists (__DIR__ . '/ ' . $ fontFile )) {
753- return __DIR__ . '/ ' . $ fontFile ;
748+ if (file_exists (__DIR__ . '/ ' . $ fontFile )) {
749+ return __DIR__ . '/ ' . $ fontFile ;
754750 }
755751 }
756752
@@ -761,54 +757,54 @@ protected function getFontByScript()
761757 {
762758 // Arabic
763759 if (StringScript::isArabic ($ this ->getInitials ())) {
764- return __DIR__ . '/fonts/script/Noto-Arabic-Regular.ttf ' ;
760+ return __DIR__ . '/fonts/script/Noto-Arabic-Regular.ttf ' ;
765761 }
766762
767763 // Armenian
768764 if (StringScript::isArmenian ($ this ->getInitials ())) {
769- return __DIR__ . '/fonts/script/Noto-Armenian-Regular.ttf ' ;
765+ return __DIR__ . '/fonts/script/Noto-Armenian-Regular.ttf ' ;
770766 }
771767
772768 // Bengali
773769 if (StringScript::isBengali ($ this ->getInitials ())) {
774- return __DIR__ . '/fonts/script/Noto-Bengali-Regular.ttf ' ;
770+ return __DIR__ . '/fonts/script/Noto-Bengali-Regular.ttf ' ;
775771 }
776772
777773 // Georgian
778774 if (StringScript::isGeorgian ($ this ->getInitials ())) {
779- return __DIR__ . '/fonts/script/Noto-Georgian-Regular.ttf ' ;
775+ return __DIR__ . '/fonts/script/Noto-Georgian-Regular.ttf ' ;
780776 }
781777
782778 // Hebrew
783779 if (StringScript::isHebrew ($ this ->getInitials ())) {
784- return __DIR__ . '/fonts/script/Noto-Hebrew-Regular.ttf ' ;
780+ return __DIR__ . '/fonts/script/Noto-Hebrew-Regular.ttf ' ;
785781 }
786782
787783 // Mongolian
788784 if (StringScript::isMongolian ($ this ->getInitials ())) {
789- return __DIR__ . '/fonts/script/Noto-Mongolian-Regular.ttf ' ;
785+ return __DIR__ . '/fonts/script/Noto-Mongolian-Regular.ttf ' ;
790786 }
791787
792788 // Thai
793789 if (StringScript::isThai ($ this ->getInitials ())) {
794- return __DIR__ . '/fonts/script/Noto-Thai-Regular.ttf ' ;
790+ return __DIR__ . '/fonts/script/Noto-Thai-Regular.ttf ' ;
795791 }
796792
797793 // Tibetan
798794 if (StringScript::isTibetan ($ this ->getInitials ())) {
799- return __DIR__ . '/fonts/script/Noto-Tibetan-Regular.ttf ' ;
795+ return __DIR__ . '/fonts/script/Noto-Tibetan-Regular.ttf ' ;
800796 }
801797
802798 // Chinese & Japanese
803799 if (StringScript::isJapanese ($ this ->getInitials ()) || StringScript::isChinese ($ this ->getInitials ())) {
804- return __DIR__ . '/fonts/script/Noto-CJKJP-Regular.otf ' ;
800+ return __DIR__ . '/fonts/script/Noto-CJKJP-Regular.otf ' ;
805801 }
806802
807803 return $ this ->getFontFile ();
808804 }
809805
810806 /**
811- * Convert HSL color value produced by autoColor() to RGB value expected by image driver
807+ * Convert HSL color value produced by autoColor() to RGB value expected by image driver.
812808 */
813809 protected function convertHSLtoRGB ($ h , $ s , $ l , $ toHex = true )
814810 {
@@ -868,17 +864,18 @@ protected function convertHSLtoRGB($h, $s, $l, $toHex = true)
868864 $ blue = round ($ blue * 255 , 0 );
869865
870866 if ($ toHex ) {
871- $ red = ($ red < 15 ) ? '0 ' . dechex ($ red ) : dechex ($ red );
872- $ green = ($ green < 15 ) ? '0 ' . dechex ($ green ) : dechex ($ green );
873- $ blue = ($ blue < 15 ) ? '0 ' . dechex ($ blue ) : dechex ($ blue );
867+ $ red = ($ red < 15 ) ? '0 ' .dechex ($ red ) : dechex ($ red );
868+ $ green = ($ green < 15 ) ? '0 ' .dechex ($ green ) : dechex ($ green );
869+ $ blue = ($ blue < 15 ) ? '0 ' .dechex ($ blue ) : dechex ($ blue );
870+
874871 return "# {$ red }{$ green }{$ blue }" ;
875872 } else {
876873 return ['red ' => $ red , 'green ' => $ green , 'blue ' => $ blue ];
877874 }
878875 }
879876
880877 /**
881- * Get contrasting foreground color for autoColor background
878+ * Get contrasting foreground color for autoColor background.
882879 */
883880 protected function getContrastColor ($ hexColor )
884881 {
@@ -889,7 +886,7 @@ protected function getContrastColor($hexColor)
889886 $ B1 = hexdec (substr ($ hexColor , 5 , 2 ));
890887
891888 // Black RGB
892- $ blackColor = " #000000 " ;
889+ $ blackColor = ' #000000 ' ;
893890 $ R2BlackColor = hexdec (substr ($ blackColor , 1 , 2 ));
894891 $ G2BlackColor = hexdec (substr ($ blackColor , 3 , 2 ));
895892 $ B2BlackColor = hexdec (substr ($ blackColor , 5 , 2 ));
@@ -905,9 +902,9 @@ protected function getContrastColor($hexColor)
905902
906903 $ contrastRatio = 0 ;
907904 if ($ L1 > $ L2 ) {
908- $ contrastRatio = (int )(($ L1 + 0.05 ) / ($ L2 + 0.05 ));
905+ $ contrastRatio = (int ) (($ L1 + 0.05 ) / ($ L2 + 0.05 ));
909906 } else {
910- $ contrastRatio = (int )(($ L2 + 0.05 ) / ($ L1 + 0.05 ));
907+ $ contrastRatio = (int ) (($ L2 + 0.05 ) / ($ L1 + 0.05 ));
911908 }
912909
913910 // If contrast is more than 5, return black color
0 commit comments