Browse Source

邀请海报

wzq 5 years ago
parent
commit
b953d2b9c7
2 changed files with 13 additions and 1 deletions
  1. 12 0
      app/Helper/helper.php
  2. 1 1
      app/Repositories/PosterRepository.php

+ 12 - 0
app/Helper/helper.php

@@ -144,3 +144,15 @@ function subtext($text, $length)
         return $text;
     }
 }
+
+function filter_Emoji($str)
+{
+    $str = preg_replace_callback(    //执行一个正则表达式搜索并且使用一个回调进行替换
+        '/./u',
+        function (array $match) {
+            return strlen($match[0]) >= 4 ? '□' : $match[0];
+        },
+        $str);
+
+    return $str;
+}

+ 1 - 1
app/Repositories/PosterRepository.php

@@ -184,7 +184,7 @@ class PosterRepository
 
         // 用户名称
         if($userInfo['username']){
-            $main->text($userInfo['username'], 30, 860, function ($font) {
+            $main->text(filter_Emoji($userInfo['username']), 30, 860, function ($font) {
                 $font->file(public_path('font/PingFang Regular.ttf'));
                 $font->size(28);
                 $font->color('#3C5852');