前端小程序
@@ -0,0 +1,13 @@
|
||||
# 品牌 Logo(CDN 托管)
|
||||
|
||||
小程序**不再打包**大图,首页 Logo 从后端 CDN 加载:
|
||||
|
||||
`https://xgsc.gynhc.com/uploads/demo/xiongge/xiongge-brand-logo.png`
|
||||
|
||||
源文件请放在后端目录,本地压缩:
|
||||
|
||||
```bash
|
||||
python public/uploads/demo/xiongge/prepare_brand_logo.py
|
||||
```
|
||||
|
||||
压缩后约 33KB(192×128),原 1536×1024 约 1.3MB 勿放入小程序包。
|
||||
|
之后 宽度: | 高度: | 大小: 8.5 KiB |
|
之后 宽度: | 高度: | 大小: 80 KiB |
|
之后 宽度: | 高度: | 大小: 56 KiB |
|
之后 宽度: | 高度: | 大小: 46 KiB |
|
之后 宽度: | 高度: | 大小: 205 KiB |
@@ -0,0 +1,112 @@
|
||||
"""Generate tab bar icons for 雄戈小酒 mini-program."""
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
SIZE = 162 # 2x for retina (display as 81px)
|
||||
CENTER = SIZE // 2
|
||||
INACTIVE = (187, 187, 187, 255) # #BBBBBB
|
||||
ACTIVE = (22, 119, 255, 255) # #1677FF 商务蓝
|
||||
STROKE = 6
|
||||
OUT_DIR = __file__.replace("generate_tabbar_icons.py", "")
|
||||
|
||||
|
||||
def new_canvas():
|
||||
return Image.new("RGBA", (SIZE, SIZE), (0, 0, 0, 0))
|
||||
|
||||
|
||||
def draw_home(draw, color, filled=False):
|
||||
roof = [(CENTER - 38, 62), (CENTER, 34), (CENTER + 38, 62)]
|
||||
if filled:
|
||||
draw.polygon(roof, fill=color)
|
||||
draw.rectangle([CENTER - 30, 62, CENTER + 30, 118], fill=color)
|
||||
else:
|
||||
draw.line([*roof, roof[0]], fill=color, width=STROKE, joint="curve")
|
||||
draw.line(
|
||||
[CENTER - 30, 62, CENTER + 30, 62, CENTER + 30, 118, CENTER - 30, 118, CENTER - 30, 62],
|
||||
fill=color,
|
||||
width=STROKE,
|
||||
joint="curve",
|
||||
)
|
||||
draw.line(
|
||||
[CENTER - 12, 82, CENTER - 12, 118, CENTER + 12, 118, CENTER + 12, 82],
|
||||
fill=color,
|
||||
width=STROKE,
|
||||
joint="curve",
|
||||
)
|
||||
|
||||
|
||||
def draw_category(draw, color, filled=False):
|
||||
gap = 10
|
||||
cell = 34
|
||||
x0 = CENTER - cell - gap // 2
|
||||
y0 = CENTER - cell - gap // 2
|
||||
rects = [
|
||||
(x0, y0, x0 + cell, y0 + cell),
|
||||
(x0 + cell + gap, y0, x0 + cell * 2 + gap, y0 + cell),
|
||||
(x0, y0 + cell + gap, x0 + cell, y0 + cell * 2 + gap),
|
||||
(x0 + cell + gap, y0 + cell + gap, x0 + cell * 2 + gap, y0 + cell * 2 + gap),
|
||||
]
|
||||
r = 8
|
||||
for rect in rects:
|
||||
if filled:
|
||||
draw.rounded_rectangle(rect, radius=r, fill=color)
|
||||
else:
|
||||
draw.rounded_rectangle(rect, radius=r, outline=color, width=STROKE)
|
||||
|
||||
|
||||
def draw_cart(draw, color, filled=False):
|
||||
top_y = 58
|
||||
draw.line([(48, top_y), (54, 46), (108, 46), (114, top_y)], fill=color, width=STROKE, joint="curve")
|
||||
if filled:
|
||||
draw.polygon([(52, top_y), (110, top_y), (102, 108), (60, 108)], fill=color)
|
||||
draw.ellipse([62, 96, 76, 110], fill=(0, 0, 0, 0))
|
||||
draw.ellipse([86, 96, 100, 110], fill=(0, 0, 0, 0))
|
||||
else:
|
||||
draw.line([52, top_y, 110, top_y, 102, 108, 60, 108, 52, top_y], fill=color, width=STROKE, joint="curve")
|
||||
draw.ellipse([62, 96, 76, 110], outline=color, width=STROKE)
|
||||
draw.ellipse([86, 96, 100, 110], outline=color, width=STROKE)
|
||||
|
||||
|
||||
def draw_user(draw, color, filled=False):
|
||||
head = [CENTER - 18, 48, CENTER + 18, 84]
|
||||
if filled:
|
||||
draw.ellipse(head, fill=color)
|
||||
draw.polygon([(CENTER - 34, 92), (CENTER + 34, 92), (CENTER + 42, 118), (CENTER - 42, 118)], fill=color)
|
||||
else:
|
||||
draw.ellipse(head, outline=color, width=STROKE)
|
||||
draw.line(
|
||||
[CENTER - 34, 92, CENTER + 34, 92, CENTER + 42, 118, CENTER - 42, 118, CENTER - 34, 92],
|
||||
fill=color,
|
||||
width=STROKE,
|
||||
joint="curve",
|
||||
)
|
||||
|
||||
|
||||
DRAWERS = {
|
||||
"home": draw_home,
|
||||
"category": draw_category,
|
||||
"cart": draw_cart,
|
||||
"personal": draw_user,
|
||||
}
|
||||
|
||||
NAMES = {
|
||||
"home": ("tabbar_home.png", "tabbar_home1.png"),
|
||||
"category": ("tabbar_category.png", "tabbar_category1.png"),
|
||||
"cart": ("tabbar_cart.png", "tabbar_cart1.png"),
|
||||
"personal": ("tabbar_personal.png", "tabbar_personal1.png"),
|
||||
}
|
||||
|
||||
|
||||
def save_icon(key, color, filled, filename):
|
||||
img = new_canvas()
|
||||
draw = ImageDraw.Draw(img)
|
||||
DRAWERS[key](draw, color, filled=filled)
|
||||
path = OUT_DIR + filename
|
||||
img.save(path, "PNG")
|
||||
print("saved", path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for key, (inactive_name, active_name) in NAMES.items():
|
||||
save_icon(key, INACTIVE, False, inactive_name)
|
||||
save_icon(key, ACTIVE, True, active_name)
|
||||
print("Done: 8 tab bar icons generated.")
|
||||
|
之后 宽度: | 高度: | 大小: 567 B |
|
之后 宽度: | 高度: | 大小: 569 B |
|
之后 宽度: | 高度: | 大小: 554 B |
|
之后 宽度: | 高度: | 大小: 523 B |
|
之后 宽度: | 高度: | 大小: 658 B |
|
之后 宽度: | 高度: | 大小: 553 B |
|
之后 宽度: | 高度: | 大小: 650 B |
|
之后 宽度: | 高度: | 大小: 537 B |
|
之后 宽度: | 高度: | 大小: 2.0 KiB |
|
之后 宽度: | 高度: | 大小: 2.0 KiB |