-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_icons.html
More file actions
76 lines (69 loc) · 2.2 KB
/
create_icons.html
File metadata and controls
76 lines (69 loc) · 2.2 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Create Icons</title>
<style>
.icon {
background-color: #4a90e2;
color: white;
font-family: Arial, sans-serif;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
margin: 10px;
}
#icon16 {
width: 16px;
height: 16px;
font-size: 12px;
}
#icon48 {
width: 48px;
height: 48px;
font-size: 36px;
}
#icon128 {
width: 128px;
height: 128px;
font-size: 96px;
}
</style>
</head>
<body>
<div id="icon16" class="icon">S</div>
<div id="icon48" class="icon">S</div>
<div id="icon128" class="icon">S</div>
<div id="output"></div>
<script>
function generateDataURL(element) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const width = element.offsetWidth;
const height = element.offsetHeight;
canvas.width = width;
canvas.height = height;
ctx.fillStyle = getComputedStyle(element).backgroundColor;
ctx.fillRect(0, 0, width, height);
ctx.font = getComputedStyle(element).font;
ctx.fillStyle = getComputedStyle(element).color;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('S', width / 2, height / 2);
return canvas.toDataURL('image/png');
}
function displayAndDownloadDataURLs() {
const sizes = [16, 48, 128];
const output = document.getElementById('output');
output.innerHTML = '';
sizes.forEach(size => {
const icon = document.getElementById(`icon${size}`);
const dataURL = generateDataURL(icon);
output.innerHTML += `<p>Icon ${size}x${size}: <a href="${dataURL}" download="icon${size}.png">Download</a></p>`;
});
}
window.onload = displayAndDownloadDataURLs;
</script>
</body>
</html>