-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_icons.html
More file actions
166 lines (145 loc) · 5.71 KB
/
generate_icons.html
File metadata and controls
166 lines (145 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TODOStack 图标生成器</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background: #f5f5f5;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.icon-preview {
display: flex;
gap: 20px;
margin: 20px 0;
flex-wrap: wrap;
}
.icon-item {
text-align: center;
padding: 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
background: #f8f9fa;
}
.icon-item canvas {
display: block;
margin: 10px auto;
border: 1px solid #ddd;
}
.download-btn {
background: #667eea;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
.download-btn:hover {
background: #5a6fd8;
}
.instructions {
background: #e3f2fd;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>TODOStack 图标生成器</h1>
<div class="instructions">
<h3>使用说明:</h3>
<p>1. 点击下方的"下载"按钮保存各个尺寸的图标</p>
<p>2. 将下载的图标文件重命名并放入 icons 文件夹:</p>
<ul>
<li>16x16 → icon16.png</li>
<li>32x32 → icon32.png</li>
<li>48x48 → icon48.png</li>
<li>128x128 → icon128.png</li>
</ul>
</div>
<div class="icon-preview" id="iconPreview">
<!-- 图标将在这里生成 -->
</div>
</div>
<script>
// SVG 图标数据
const svgData = `
<svg width="128" height="128" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#667eea;stop-opacity:1" />
<stop offset="100%" style="stop-color:#764ba2;stop-opacity:1" />
</linearGradient>
</defs>
<circle cx="64" cy="64" r="60" fill="url(#gradient)"/>
<rect x="20" y="85" width="88" height="12" rx="6" fill="#ffffff" opacity="0.9"/>
<rect x="24" y="70" width="80" height="12" rx="6" fill="#ffffff" opacity="0.95"/>
<rect x="28" y="55" width="72" height="12" rx="6" fill="#ffffff"/>
<polygon points="64,35 70,45 58,45" fill="#ffd700"/>
<text x="64" y="32" text-anchor="middle" fill="#ffd700" font-family="Arial, sans-serif" font-size="10" font-weight="bold">TOP</text>
<line x1="20" y1="85" x2="20" y2="97" stroke="#ffffff" stroke-width="2" opacity="0.7"/>
<line x1="108" y1="85" x2="108" y2="97" stroke="#ffffff" stroke-width="2" opacity="0.7"/>
<circle cx="45" cy="61" r="2" fill="#ffd700" opacity="0.8"/>
<circle cx="83" cy="76" r="2" fill="#ffd700" opacity="0.8"/>
<circle cx="64" cy="91" r="2" fill="#ffd700" opacity="0.8"/>
</svg>`;
// 图标尺寸
const sizes = [16, 32, 48, 128];
// 生成图标
function generateIcons() {
const container = document.getElementById('iconPreview');
sizes.forEach(size => {
const iconItem = document.createElement('div');
iconItem.className = 'icon-item';
const canvas = document.createElement('canvas');
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext('2d');
// 创建图像
const img = new Image();
const svgBlob = new Blob([svgData], {type: 'image/svg+xml'});
const url = URL.createObjectURL(svgBlob);
img.onload = function() {
ctx.drawImage(img, 0, 0, size, size);
URL.revokeObjectURL(url);
};
img.src = url;
const label = document.createElement('div');
label.textContent = `${size}x${size}`;
label.style.fontWeight = 'bold';
label.style.marginBottom = '5px';
const downloadBtn = document.createElement('button');
downloadBtn.className = 'download-btn';
downloadBtn.textContent = '下载';
downloadBtn.onclick = () => downloadIcon(canvas, `icon${size}.png`);
iconItem.appendChild(label);
iconItem.appendChild(canvas);
iconItem.appendChild(downloadBtn);
container.appendChild(iconItem);
});
}
// 下载图标
function downloadIcon(canvas, filename) {
const link = document.createElement('a');
link.download = filename;
link.href = canvas.toDataURL('image/png');
link.click();
}
// 页面加载完成后生成图标
window.onload = generateIcons;
</script>
</body>
</html>