WIN-2308041133\Administrator 4 giorni fa
parent
commit
a419fec32f

+ 6 - 6
app/api/controller/user/UserBillController.php

@@ -214,8 +214,8 @@ class UserBillController
                             array(  // 圆形头像
                                 'url' => $avatarUrl,
                                 'stream' => 0,
-                                'left' => 240,    // 调整:与昵称对齐左边
-                                'top' => 720,     // 调整:昵称下方
+                                'left' => 240,    // 水平居中位置
+                                'top' => 650,     // 上移:从720改为650
                                 'right' => 0,
                                 'bottom' => 0,
                                 'width' => 70,
@@ -238,8 +238,8 @@ class UserBillController
                         'text' => array(
                             array(
                                 'text' => $user['nickname'],
-                                'left' => 240,  // 头像左边对齐
-                                'top' => 700,   // 头像上方20px
+                                'left' => 240,
+                                'top' => 630,   // 头像上方20px
                                 'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'],
                                 'fontSize' => 16,
                                 'fontColor' => '40,40,40',
@@ -328,7 +328,7 @@ class UserBillController
                                 'url' => $avatarUrl,
                                 'stream' => 0,
                                 'left' => 300,    // 居中位置:(750-150)/2 = 300
-                                'top' => 640,     // 名字下方
+                                'top' => 500,     // 上移:从640改为500
                                 'right' => 0,
                                 'bottom' => 0,
                                 'width' => 150,
@@ -352,7 +352,7 @@ class UserBillController
                             array(
                                 'text' => $nickname,
                                 'left' => 300,   // 与头像左边对齐
-                                'top' => 620,    // 头像上方20px
+                                'top' => 480,    // 头像上方20px
                                 'fontPath' => $fontBoldPath,
                                 'fontSize' => 50,
                                 'fontColor' => '40,40,40',

+ 21 - 10
crmeb/services/UtilService.php

@@ -338,21 +338,29 @@ class UtilService
                 $resWidth = $info[0];
                 $resHeight = $info[1];
 
-                // 如果是圆形,先创建圆形图片
+// 如果是圆形,先创建圆形图片
                 if ($val['circle']) {
                     // 创建一个正方形的画布
                     $canvas = imagecreatetruecolor($val['width'], $val['height']);
 
-                    // 创建透明背景
-                    imagesavealpha($canvas, true);
-                    $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
-                    imagefill($canvas, 0, 0, $transparent);
+                    // 创建白色背景(与海报背景相同)
+                    $bgColor = imagecolorallocate($canvas, 255, 255, 255);
+                    imagefill($canvas, 0, 0, $bgColor);
 
                     // 将原图缩放到指定大小
                     $sourceResized = imagecreatetruecolor($val['width'], $val['height']);
                     imagecopyresampled($sourceResized, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
 
-                    // 创建圆形
+                    // 创建圆形蒙版
+                    $mask = imagecreatetruecolor($val['width'], $val['height']);
+                    $transparent = imagecolorallocate($mask, 255, 255, 255); // 白色背景
+                    imagefill($mask, 0, 0, $transparent);
+
+                    // 绘制圆形(黑色)
+                    $black = imagecolorallocate($mask, 0, 0, 0);
+                    imagefilledellipse($mask, $val['width']/2, $val['height']/2, $val['width'], $val['height'], $black);
+
+                    // 将原图应用到圆形蒙版
                     $centerX = $val['width'] / 2;
                     $centerY = $val['height'] / 2;
                     $radius = min($val['width'], $val['height']) / 2;
@@ -367,18 +375,21 @@ class UtilService
                         }
                     }
 
-                    // 添加白色边框(可选)
+                    // 添加白色边框(可选,增加美观度
                     $borderColor = imagecolorallocate($canvas, 255, 255, 255);
-                    $borderRadius = $radius + 1;
+                    $borderRadius = $radius;
                     for ($angle = 0; $angle < 360; $angle += 1) {
                         $x = $centerX + $borderRadius * cos(deg2rad($angle));
                         $y = $centerY + $borderRadius * sin(deg2rad($angle));
-                        imagesetpixel($canvas, $x, $y, $borderColor);
+                        if ($x >= 0 && $x < $val['width'] && $y >= 0 && $y < $val['height']) {
+                            imagesetpixel($canvas, $x, $y, $borderColor);
+                        }
                     }
 
                     imagedestroy($sourceResized);
+                    imagedestroy($mask);
                     imagedestroy($res);
-                } else {
+                }else {
                     // 非圆形,按原逻辑处理
                     $canvas = imagecreatetruecolor($val['width'], $val['height']);
                     $bgColor = imagecolorallocate($canvas, 255, 255, 255);