|
|
@@ -340,27 +340,19 @@ class UtilService
|
|
|
|
|
|
// 如果是圆形,先创建圆形图片
|
|
|
if ($val['circle']) {
|
|
|
- // 创建一个正方形的画布
|
|
|
+ // 创建一个支持透明的画布
|
|
|
$canvas = imagecreatetruecolor($val['width'], $val['height']);
|
|
|
|
|
|
- // 创建白色背景(与海报背景相同)
|
|
|
- $bgColor = imagecolorallocate($canvas, 255, 255, 255);
|
|
|
- imagefill($canvas, 0, 0, $bgColor);
|
|
|
+ // 设置画布为透明背景
|
|
|
+ imagesavealpha($canvas, true);
|
|
|
+ $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
|
|
|
+ imagefill($canvas, 0, 0, $transparent);
|
|
|
|
|
|
// 将原图缩放到指定大小
|
|
|
$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;
|
|
|
@@ -375,19 +367,7 @@ class UtilService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 添加白色边框(可选,增加美观度)
|
|
|
- $borderColor = imagecolorallocate($canvas, 255, 255, 255);
|
|
|
- $borderRadius = $radius;
|
|
|
- for ($angle = 0; $angle < 360; $angle += 1) {
|
|
|
- $x = $centerX + $borderRadius * cos(deg2rad($angle));
|
|
|
- $y = $centerY + $borderRadius * sin(deg2rad($angle));
|
|
|
- if ($x >= 0 && $x < $val['width'] && $y >= 0 && $y < $val['height']) {
|
|
|
- imagesetpixel($canvas, $x, $y, $borderColor);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
imagedestroy($sourceResized);
|
|
|
- imagedestroy($mask);
|
|
|
imagedestroy($res);
|
|
|
}else {
|
|
|
// 非圆形,按原逻辑处理
|