-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-maskable-icon.html
More file actions
177 lines (151 loc) · 6.29 KB
/
create-maskable-icon.html
File metadata and controls
177 lines (151 loc) · 6.29 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
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html>
<head>
<title>Create Maskable Icon</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
canvas { border: 1px solid #ccc; margin: 10px 0; }
.info { background: #f0f0f0; padding: 15px; margin: 10px 0; border-radius: 5px; }
button { padding: 10px 20px; margin: 5px; cursor: pointer; }
</style>
</head>
<body>
<h1>SafeNote Maskable Icon Generator</h1>
<div class="info">
<h3>📱 Maskable Icon Requirements:</h3>
<ul>
<li><strong>Safe Zone:</strong> At least 10% padding on all sides</li>
<li><strong>Content Area:</strong> Logo should fit in center 80% of the icon</li>
<li><strong>Background:</strong> Should work on any background (use contrasting colors)</li>
</ul>
</div>
<div>
<label>Select original SafeNote icon:</label>
<input type="file" id="fileInput" accept="image/*">
</div>
<div>
<label>Background Color:</label>
<select id="bgColor">
<option value="#000000">Black</option>
<option value="#1e293b" selected>Dark Blue (Theme)</option>
<option value="#ffffff">White</option>
<option value="#6366f1">Purple</option>
</select>
</div>
<div>
<label>Padding (%):</label>
<input type="range" id="padding" min="10" max="30" value="15" oninput="updatePadding()">
<span id="paddingValue">15%</span>
</div>
<canvas id="canvas" width="512" height="512"></canvas>
<div>
<button onclick="generateIcon()">Generate Maskable Icon</button>
<button onclick="downloadIcon()">Download Icon</button>
<button onclick="testMasks()">Test with Masks</button>
</div>
<div id="testArea" style="display:none;">
<h3>🔍 Test Different Masks:</h3>
<div style="display: flex; gap: 20px; flex-wrap: wrap;">
<div>
<p>Circle Mask</p>
<canvas id="circleTest" width="100" height="100" style="border-radius: 50%;"></canvas>
</div>
<div>
<p>Rounded Square</p>
<canvas id="roundedTest" width="100" height="100" style="border-radius: 20%;"></canvas>
</div>
<div>
<p>Square</p>
<canvas id="squareTest" width="100" height="100"></canvas>
</div>
</div>
</div>
<script>
let originalImage = null;
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
document.getElementById('fileInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
originalImage = img;
generateIcon();
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
});
function updatePadding() {
const value = document.getElementById('padding').value;
document.getElementById('paddingValue').textContent = value + '%';
if (originalImage) generateIcon();
}
function generateIcon() {
if (!originalImage) return;
const padding = parseInt(document.getElementById('padding').value);
const bgColor = document.getElementById('bgColor').value;
// Clear canvas and set background
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, 512, 512);
// Calculate dimensions with padding
const paddingPx = (512 * padding) / 100;
const logoSize = 512 - (paddingPx * 2);
// Draw the original image centered with padding
ctx.drawImage(originalImage, paddingPx, paddingPx, logoSize, logoSize);
// Draw safe zone guides
ctx.strokeStyle = 'rgba(255, 0, 0, 0.3)';
ctx.lineWidth = 2;
ctx.setLineDash([10, 5]);
ctx.strokeRect(paddingPx, paddingPx, logoSize, logoSize);
// Draw center guides
ctx.strokeStyle = 'rgba(0, 255, 0, 0.3)';
ctx.setLineDash([5, 5]);
ctx.beginPath();
ctx.moveTo(256, 0);
ctx.lineTo(256, 512);
ctx.moveTo(0, 256);
ctx.lineTo(512, 256);
ctx.stroke();
ctx.setLineDash([]);
}
function downloadIcon() {
if (!originalImage) {
alert('Please select an image first!');
return;
}
// Create a clean version without guides
const tempCanvas = document.createElement('canvas');
tempCanvas.width = 512;
tempCanvas.height = 512;
const tempCtx = tempCanvas.getContext('2d');
const padding = parseInt(document.getElementById('padding').value);
const bgColor = document.getElementById('bgColor').value;
const paddingPx = (512 * padding) / 100;
const logoSize = 512 - (paddingPx * 2);
tempCtx.fillStyle = bgColor;
tempCtx.fillRect(0, 0, 512, 512);
tempCtx.drawImage(originalImage, paddingPx, paddingPx, logoSize, logoSize);
// Download
const link = document.createElement('a');
link.download = 'safenote-maskable.png';
link.href = tempCanvas.toDataURL();
link.click();
}
function testMasks() {
if (!originalImage) return;
document.getElementById('testArea').style.display = 'block';
const tests = ['circleTest', 'roundedTest', 'squareTest'];
tests.forEach(testId => {
const testCanvas = document.getElementById(testId);
const testCtx = testCanvas.getContext('2d');
// Scale down the main canvas to 100x100
testCtx.drawImage(canvas, 0, 0, 100, 100);
});
}
</script>
</body>
</html>