|
|
@@ -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);
|