WIN-2308041133\Administrator 3 days ago
parent
commit
706b58914b
2 changed files with 53 additions and 57 deletions
  1. 32 32
      app/api/controller/user/UserBillController.php
  2. 21 25
      crmeb/services/UtilService.php

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

@@ -211,11 +211,11 @@ class UserBillController
                     $posterInfo = '海报生成失败:(';
                     $config = array(
                         'image' => array(
-                            array(  // ===== 新增:圆形头像(右上位置,适配小海报) =====
+                            array(  // 圆形头像
                                 'url' => $avatarUrl,
                                 'stream' => 0,
                                 'left' => 240,    // 调整:与昵称对齐左边
-                                'top' => 720,     // 调整:昵称上方,避免重叠
+                                'top' => 720,     // 调整:昵称下方
                                 'right' => 0,
                                 'bottom' => 0,
                                 'width' => 70,
@@ -238,20 +238,20 @@ class UserBillController
                         'text' => array(
                             array(
                                 'text' => $user['nickname'],
-                                'left' => 250,
-                                'top' => 840,
-                                'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'],     //字体文件
-                                'fontSize' => 16,             //字号
-                                'fontColor' => '40,40,40',       //字体颜色
+                                'left' => 240,  // 头像左边对齐
+                                'top' => 700,   // 头像上方20px
+                                'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'],
+                                'fontSize' => 16,
+                                'fontColor' => '40,40,40',
                                 'angle' => 0,
                             ),
                             array(
                                 'text' => '邀请您加入' . sys_config('site_name'),
                                 'left' => 250,
                                 'top' => 880,
-                                'fontPath' => $rootPath . 'public' . DS . $filelink['Normal'],     //字体文件
-                                'fontSize' => 16,             //字号
-                                'fontColor' => '40,40,40',       //字体颜色
+                                'fontPath' => $rootPath . 'public' . DS . $filelink['Normal'],
+                                'fontSize' => 16,
+                                'fontColor' => '40,40,40',
                                 'angle' => 0,
                             )
                         ),
@@ -324,11 +324,11 @@ class UserBillController
                     $posterInfo = '海报生成失败:(';
                     $config = array(
                         'image' => array(
-                            array(  // ===== 新增:圆形头像(左上位置,适配大海报) =====
+                            array(  // 圆形头像
                                 'url' => $avatarUrl,
                                 'stream' => 0,
-                                'left' => 120,    // 调整:与文字对齐
-                                'top' => 50,      // 调整:海报顶部
+                                'left' => 300,    // 居中位置:(750-150)/2 = 300
+                                'top' => 640,     // 名字下方
                                 'right' => 0,
                                 'bottom' => 0,
                                 'width' => 150,
@@ -350,26 +350,26 @@ class UserBillController
                         ),
                         'text' => array(
                             array(
-                                    'text' => $nickname,
-                                    'left' => $nicknameLeft,   // 动态居中!
-                                    'top' => 640,
-                                    'fontPath' => $fontBoldPath,
-                                    'fontSize' => 50, 'fontColor' => '40,40,40',
-                                    'angle' => 0,
-                                ),
-                                array(
-                                    'text' => '邀请您加入' . sys_config('site_name'),
-//                                'text' => '',
-                                    'left' => 120,
-                                    'top' => 720,
-                                    'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'],  // 加粗字体
-                                    'fontSize' => 40,             //字号
-                                    'fontColor' => '40,40,40',       //字体颜色
-                                    'angle' => 0,
-                                )
+                                'text' => $nickname,
+                                'left' => 300,   // 与头像左边对齐
+                                'top' => 620,    // 头像上方20px
+                                'fontPath' => $fontBoldPath,
+                                'fontSize' => 50,
+                                'fontColor' => '40,40,40',
+                                'angle' => 0,
                             ),
-                            'background' => $item['pic']
-                        );
+                            array(
+                                'text' => '邀请您加入' . sys_config('site_name'),
+                                'left' => 120,
+                                'top' => 720,
+                                'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'],
+                                'fontSize' => 40,
+                                'fontColor' => '40,40,40',
+                                'angle' => 0,
+                            )
+                        ),
+                        'background' => $item['pic']
+                    );
                     $resWap = $resWap && $posterInfo = UtilService::setSharePoster($config, 'wap/spread/poster');
                     if (!is_array($posterInfo)) return app('json')->fail($posterInfo);
                     SystemAttachment::attachmentAdd($posterInfo['name'], $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2);

+ 21 - 25
crmeb/services/UtilService.php

@@ -340,7 +340,7 @@ class UtilService
 
                 // 如果是圆形,先创建圆形图片
                 if ($val['circle']) {
-                    // 创建一个新的画布用于圆形头像
+                    // 创建一个正方形的画布
                     $canvas = imagecreatetruecolor($val['width'], $val['height']);
 
                     // 创建透明背景
@@ -348,44 +348,40 @@ class UtilService
                     $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
                     imagefill($canvas, 0, 0, $transparent);
 
-                    // 创建圆形蒙版
-                    $mask = imagecreatetruecolor($val['width'], $val['height']);
-                    imagefill($mask, 0, 0, imagecolorallocate($mask, 255, 0, 0));
-
-                    // 绘制圆形
-                    imagefilledellipse($mask, $val['width']/2, $val['height']/2, $val['width'], $val['height'], imagecolorallocate($mask, 0, 0, 0));
-
-                    // 设置红色为透明色
-                    imagecolortransparent($mask, imagecolorallocate($mask, 255, 0, 0));
-
-                    // 将原图缩放到圆形大小
+                    // 将原图缩放到指定大小
                     $sourceResized = imagecreatetruecolor($val['width'], $val['height']);
                     imagecopyresampled($sourceResized, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
 
-                    // 应用圆形蒙版
-                    imagecopy($canvas, $sourceResized, 0, 0, 0, 0, $val['width'], $val['height']);
-                    imagecopymerge($canvas, $mask, 0, 0, 0, 0, $val['width'], $val['height'], 100);
+                    // 创建圆形
+                    $centerX = $val['width'] / 2;
+                    $centerY = $val['height'] / 2;
+                    $radius = min($val['width'], $val['height']) / 2;
 
-                    // 将透明背景设置为白色(可选)
-                    $white = imagecolorallocate($canvas, 255, 255, 255);
                     for ($x = 0; $x < $val['width']; $x++) {
                         for ($y = 0; $y < $val['height']; $y++) {
-                            $rgba = imagecolorat($canvas, $x, $y);
-                            $alpha = ($rgba >> 24) & 0x7F;
-                            if ($alpha > 100) {
-                                imagesetpixel($canvas, $x, $y, $white);
+                            $distance = sqrt(pow($x - $centerX, 2) + pow($y - $centerY, 2));
+                            if ($distance <= $radius) {
+                                $color = imagecolorat($sourceResized, $x, $y);
+                                imagesetpixel($canvas, $x, $y, $color);
                             }
                         }
                     }
 
+                    // 添加白色边框(可选)
+                    $borderColor = imagecolorallocate($canvas, 255, 255, 255);
+                    $borderRadius = $radius + 1;
+                    for ($angle = 0; $angle < 360; $angle += 1) {
+                        $x = $centerX + $borderRadius * cos(deg2rad($angle));
+                        $y = $centerY + $borderRadius * sin(deg2rad($angle));
+                        imagesetpixel($canvas, $x, $y, $borderColor);
+                    }
+
                     imagedestroy($sourceResized);
-                    imagedestroy($mask);
                     imagedestroy($res);
                 } else {
                     // 非圆形,按原逻辑处理
                     $canvas = imagecreatetruecolor($val['width'], $val['height']);
-                    // 修正这里:使用正确的颜色填充
-                    $bgColor = imagecolorallocate($canvas, 255, 255, 255); // 使用白色背景
+                    $bgColor = imagecolorallocate($canvas, 255, 255, 255);
                     imagefill($canvas, 0, 0, $bgColor);
                     imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
                     imagedestroy($res);
@@ -394,7 +390,7 @@ class UtilService
                 $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) - $val['width'] : $val['left'];
                 $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) - $val['height'] : $val['top'];
 
-                // 修正:使用正确的imagecopymerge参数
+                // 合并到主图像
                 imagecopymerge($imageRes, $canvas, $val['left'], $val['top'], 0, 0, $val['width'], $val['height'], $val['opacity']);
 
                 imagedestroy($canvas);