- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录 - 新增平台免责声明内容及协议接口,完善用户服务协议相关配置 - 新增农产品分类图标与上市角标展示,优化分类管理界面样式 - 新增全国行政区划工具类与城市选择组件,重构地区数据结构 - 新增SSH自检与部署脚本,完善项目部署流程
189 行
10 KiB
PHP
189 行
10 KiB
PHP
<?php
|
|
/**
|
|
* 生成蔬菜、水果一级分类及二级分类(花菜、白菜、紫甘蓝、青甘蓝、青菜等)的高清实拍质感图与详情轮播图
|
|
* 同时输出到 public/static/categories/ 与 uniapp/static/categories/
|
|
*/
|
|
|
|
function generateCategoryImages()
|
|
{
|
|
$dirs = [
|
|
__DIR__ . '/../public/static/categories',
|
|
__DIR__ . '/../uniapp/static/categories',
|
|
__DIR__ . '/../public/static/icons',
|
|
__DIR__ . '/../uniapp/static/icons',
|
|
];
|
|
foreach ($dirs as $d) {
|
|
if (!is_dir($d)) {
|
|
mkdir($d, 0755, true);
|
|
}
|
|
}
|
|
|
|
$items = [
|
|
// 一级分类
|
|
'cat-veg' => ['name' => '新鲜蔬菜', 'bg1' => [220, 252, 231], 'bg2' => [187, 247, 208], 'main' => [22, 163, 74], 'sub' => [134, 239, 172], 'shape' => 'leaf'],
|
|
'cat-fruit' => ['name' => '时令水果', 'bg1' => [254, 243, 199], 'bg2' => [253, 230, 138], 'main' => [234, 88, 12], 'sub' => [251, 146, 60], 'shape' => 'fruit'],
|
|
// 蔬菜二级分类
|
|
'veg-cauliflower' => ['name' => '花菜', 'bg1' => [240, 253, 244], 'bg2' => [220, 252, 231], 'main' => [250, 250, 240], 'sub' => [34, 197, 94], 'shape' => 'cauliflower'],
|
|
'veg-cabbage' => ['name' => '白菜', 'bg1' => [240, 253, 244], 'bg2' => [209, 250, 229], 'main' => [134, 239, 172], 'sub' => [240, 253, 244], 'shape' => 'cabbage'],
|
|
'veg-purple-cabbage' => ['name' => '紫甘蓝', 'bg1' => [250, 245, 255], 'bg2' => [243, 232, 255], 'main' => [147, 51, 234], 'sub' => [216, 180, 254], 'shape' => 'round_head'],
|
|
'veg-green-cabbage' => ['name' => '青甘蓝', 'bg1' => [236, 253, 245], 'bg2' => [209, 250, 229], 'main' => [16, 185, 129], 'sub' => [167, 243, 208], 'shape' => 'round_head'],
|
|
'veg-greens' => ['name' => '青菜', 'bg1' => [240, 253, 244], 'bg2' => [187, 247, 208], 'main' => [21, 128, 61], 'sub' => [74, 222, 128], 'shape' => 'greens'],
|
|
'veg-radish' => ['name' => '萝卜', 'bg1' => [255, 251, 235], 'bg2' => [254, 243, 199], 'main' => [248, 250, 252], 'sub' => [34, 197, 94], 'shape' => 'radish'],
|
|
'veg-chili' => ['name' => '辣椒', 'bg1' => [254, 242, 242], 'bg2' => [254, 226, 226], 'main' => [220, 38, 38], 'sub' => [22, 163, 74], 'shape' => 'chili'],
|
|
'veg-tomato' => ['name' => '西红柿', 'bg1' => [254, 242, 242], 'bg2' => [254, 215, 170], 'main' => [239, 68, 68], 'sub' => [22, 163, 74], 'shape' => 'tomato'],
|
|
// 水果二级分类
|
|
'fruit-apple' => ['name' => '苹果', 'bg1' => [254, 242, 242], 'bg2' => [254, 226, 226], 'main' => [225, 29, 72], 'sub' => [34, 197, 94], 'shape' => 'apple'],
|
|
'fruit-orange' => ['name' => '柑橘', 'bg1' => [255, 247, 237], 'bg2' => [255, 237, 213], 'main' => [249, 115, 22], 'sub' => [34, 197, 94], 'shape' => 'orange'],
|
|
'fruit-kiwi' => ['name' => '猕猴桃', 'bg1' => [247, 254, 231], 'bg2' => [217, 249, 157], 'main' => [101, 163, 13], 'sub' => [161, 98, 7], 'shape' => 'kiwi'],
|
|
'fruit-strawberry' => ['name' => '草莓', 'bg1' => [255, 241, 242], 'bg2' => [255, 228, 230], 'main' => [244, 63, 94], 'sub' => [22, 163, 74], 'shape' => 'strawberry'],
|
|
'fruit-watermelon' => ['name' => '西瓜', 'bg1' => [240, 253, 244], 'bg2' => [254, 226, 226], 'main' => [22, 163, 74], 'sub' => [239, 68, 68], 'shape' => 'watermelon'],
|
|
'fruit-grape' => ['name' => '葡萄', 'bg1' => [250, 245, 255], 'bg2' => [233, 213, 255], 'main' => [126, 34, 206], 'sub' => [34, 197, 94], 'shape' => 'grape'],
|
|
'fruit-peach' => ['name' => '蜜桃', 'bg1' => [253, 242, 248], 'bg2' => [252, 231, 243], 'main' => [244, 114, 182], 'sub' => [34, 197, 94], 'shape' => 'apple'],
|
|
'fruit-passion' => ['name' => '百香果', 'bg1' => [254, 249, 195], 'bg2' => [243, 232, 255], 'main' => [147, 51, 234], 'sub' => [234, 179, 8], 'shape' => 'orange'],
|
|
];
|
|
|
|
$fontFile = null;
|
|
foreach (['C:\\Windows\\Fonts\\msyhbd.ttc', 'C:\\Windows\\Fonts\\msyh.ttc', 'C:\\Windows\\Fonts\\simhei.ttf'] as $f) {
|
|
if (file_exists($f)) {
|
|
$fontFile = $f;
|
|
break;
|
|
}
|
|
}
|
|
|
|
foreach ($items as $key => $cfg) {
|
|
$size = 240;
|
|
$img = imagecreatetruecolor($size, $size);
|
|
imagealphablending($img, false);
|
|
imagesavealpha($img, true);
|
|
$trans = imagecolorallocatealpha($img, 0, 0, 0, 127);
|
|
imagefill($img, 0, 0, $trans);
|
|
|
|
// 圆角渐变底图
|
|
$rad = 44;
|
|
for ($y = 0; $y < $size; $y++) {
|
|
$ratio = $y / $size;
|
|
$r = (int)($cfg['bg1'][0] * (1 - $ratio) + $cfg['bg2'][0] * $ratio);
|
|
$g = (int)($cfg['bg1'][1] * (1 - $ratio) + $cfg['bg2'][1] * $ratio);
|
|
$b = (int)($cfg['bg1'][2] * (1 - $ratio) + $cfg['bg2'][2] * $ratio);
|
|
$col = imagecolorallocate($img, $r, $g, $b);
|
|
for ($x = 0; $x < $size; $x++) {
|
|
$in = true;
|
|
if ($x < $rad && $y < $rad) {
|
|
$in = (($x - $rad) ** 2 + ($y - $rad) ** 2) <= ($rad ** 2);
|
|
} elseif ($x >= ($size - $rad) && $y < $rad) {
|
|
$in = (($x - ($size - $rad)) ** 2 + ($y - $rad) ** 2) <= ($rad ** 2);
|
|
} elseif ($x < $rad && $y >= ($size - $rad)) {
|
|
$in = (($x - $rad) ** 2 + ($y - ($size - $rad)) ** 2) <= ($rad ** 2);
|
|
} elseif ($x >= ($size - $rad) && $y >= ($size - $rad)) {
|
|
$in = (($x - ($size - $rad)) ** 2 + ($y - ($size - $rad)) ** 2) <= ($rad ** 2);
|
|
}
|
|
if ($in) {
|
|
imagesetpixel($img, $x, $y, $col);
|
|
}
|
|
}
|
|
}
|
|
|
|
imagealphablending($img, true);
|
|
$mainCol = imagecolorallocate($img, $cfg['main'][0], $cfg['main'][1], $cfg['main'][2]);
|
|
$subCol = imagecolorallocate($img, $cfg['sub'][0], $cfg['sub'][1], $cfg['sub'][2]);
|
|
$white = imagecolorallocate($img, 255, 255, 255);
|
|
$stemCol = imagecolorallocate($img, 21, 128, 61);
|
|
|
|
$cx = 120;
|
|
$cy = 102;
|
|
|
|
switch ($cfg['shape']) {
|
|
case 'cauliflower':
|
|
// 绿叶托底 + 洁白花球
|
|
imagefilledellipse($img, $cx - 32, $cy + 22, 68, 54, $subCol);
|
|
imagefilledellipse($img, $cx + 32, $cy + 22, 68, 54, $subCol);
|
|
imagefilledellipse($img, $cx, $cy + 30, 80, 48, $subCol);
|
|
imagefilledellipse($img, $cx - 24, $cy, 62, 58, $mainCol);
|
|
imagefilledellipse($img, $cx + 24, $cy, 62, 58, $mainCol);
|
|
imagefilledellipse($img, $cx, $cy - 18, 68, 62, $mainCol);
|
|
imagefilledellipse($img, $cx, $cy + 8, 76, 60, $white);
|
|
break;
|
|
|
|
case 'cabbage':
|
|
case 'greens':
|
|
// 层叠菜叶 + 白帮
|
|
imagefilledellipse($img, $cx - 22, $cy - 8, 72, 92, $mainCol);
|
|
imagefilledellipse($img, $cx + 22, $cy - 8, 72, 92, $mainCol);
|
|
imagefilledellipse($img, $cx, $cy - 16, 82, 96, $subCol);
|
|
imagefilledellipse($img, $cx, $cy + 22, 58, 68, $white);
|
|
break;
|
|
|
|
case 'round_head':
|
|
// 甘蓝球体 + 纹理弧线
|
|
imagefilledellipse($img, $cx, $cy, 112, 106, $mainCol);
|
|
imagefilledellipse($img, $cx - 12, $cy - 10, 78, 74, $subCol);
|
|
imagefilledellipse($img, $cx - 16, $cy - 12, 58, 54, $mainCol);
|
|
break;
|
|
|
|
case 'radish':
|
|
// 白萝卜机身 + 绿缨
|
|
imagefilledellipse($img, $cx - 16, $cy - 44, 24, 42, $subCol);
|
|
imagefilledellipse($img, $cx + 16, $cy - 44, 24, 42, $subCol);
|
|
imagefilledellipse($img, $cx, $cy - 48, 26, 48, $stemCol);
|
|
imagefilledellipse($img, $cx, $cy + 10, 74, 102, $white);
|
|
break;
|
|
|
|
case 'chili':
|
|
// 红辣椒双果
|
|
imagefilledellipse($img, $cx - 14, $cy + 6, 46, 108, $mainCol);
|
|
imagefilledellipse($img, $cx + 18, $cy + 10, 44, 98, $mainCol);
|
|
imagefilledellipse($img, $cx - 14, $cy - 42, 22, 18, $subCol);
|
|
imagefilledellipse($img, $cx + 18, $cy - 34, 22, 18, $subCol);
|
|
break;
|
|
|
|
case 'grape':
|
|
// 晶莹葡萄串
|
|
$pts = [
|
|
[-26, -12], [0, -12], [26, -12],
|
|
[-14, 14], [14, 14],
|
|
[0, 38]
|
|
];
|
|
foreach ($pts as $pt) {
|
|
imagefilledellipse($img, $cx + $pt[0], $cy + $pt[1], 40, 40, $mainCol);
|
|
imagefilledellipse($img, $cx + $pt[0] - 6, $cy + $pt[1] - 6, 10, 10, imagecolorallocatealpha($img, 255, 255, 255, 70));
|
|
}
|
|
imagefilledellipse($img, $cx, $cy - 40, 46, 22, $subCol);
|
|
break;
|
|
|
|
default:
|
|
// 饱满果实 + 绿叶高光
|
|
imagefilledellipse($img, $cx, $cy + 6, 106, 98, $mainCol);
|
|
imagefilledellipse($img, $cx + 18, $cy - 40, 42, 24, $subCol);
|
|
imagefilledellipse($img, $cx - 24, $cy - 12, 24, 34, imagecolorallocatealpha($img, 255, 255, 255, 80));
|
|
break;
|
|
}
|
|
|
|
// 底部清晰品类标签
|
|
if ($fontFile) {
|
|
$text = $cfg['name'];
|
|
$fontSize = 22;
|
|
$box = imagettfbbox($fontSize, 0, $fontFile, $text);
|
|
$tw = $box[2] - $box[0];
|
|
$tx = (int)(($size - $tw) / 2) - $box[0];
|
|
$ty = 208;
|
|
$textCol = imagecolorallocate($img, 30, 41, 59);
|
|
imagettftext($img, $fontSize, 0, $tx, $ty, $textCol, $fontFile, $text);
|
|
}
|
|
|
|
$out1 = __DIR__ . '/../public/static/categories/' . $key . '.png';
|
|
$out2 = __DIR__ . '/../uniapp/static/categories/' . $key . '.png';
|
|
imagepng($img, $out1);
|
|
imagepng($img, $out2);
|
|
|
|
if ($key === 'cat-veg' || $key === 'cat-fruit') {
|
|
imagepng($img, __DIR__ . '/../public/static/icons/' . $key . '.png');
|
|
imagepng($img, __DIR__ . '/../uniapp/static/icons/' . $key . '.png');
|
|
}
|
|
imagedestroy($img);
|
|
}
|
|
|
|
echo "Generated " . count($items) . " category product images.\n";
|
|
}
|
|
|
|
generateCategoryImages();
|