TKK_E32231503/create_adaptive_icon.html

186 lines
6.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Android Adaptive Icon Generator</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #1976D2;
text-align: center;
}
.preview {
display: flex;
justify-content: space-around;
margin: 30px 0;
}
.icon-preview {
text-align: center;
}
canvas {
border: 2px solid #ddd;
border-radius: 10px;
margin: 10px;
}
input[type="file"] {
display: block;
margin: 20px auto;
padding: 10px;
}
button {
background: #1976D2;
color: white;
border: none;
padding: 12px 30px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
display: block;
margin: 20px auto;
}
button:hover {
background: #1565C0;
}
.info {
background: #E3F2FD;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.safe-zone {
position: absolute;
border: 3px dashed #FF5722;
border-radius: 50%;
pointer-events: none;
}
</style>
</head>
<body>
<div class="container">
<h1>🎨 Android Adaptive Icon Generator</h1>
<div class="info">
<strong>📱 Android Adaptive Icon Safe Zone:</strong><br>
Your icon will be displayed in different shapes (circle, square, squircle).<br>
Important content must stay within the <span style="color: #FF5722;">red circle</span> (66% area).
</div>
<input type="file" id="imageInput" accept="image/*">
<div class="preview">
<div class="icon-preview">
<h3>Original</h3>
<canvas id="originalCanvas" width="300" height="300"></canvas>
</div>
<div class="icon-preview">
<h3>Adaptive Icon (66% size)</h3>
<div style="position: relative; display: inline-block;">
<canvas id="adaptiveCanvas" width="300" height="300"></canvas>
<div class="safe-zone" style="width: 198px; height: 198px; top: 51px; left: 51px;"></div>
</div>
</div>
</div>
<button onclick="downloadIcon()">⬇️ Download Fixed Icon (1024x1024)</button>
<div class="info">
<strong>Next steps after download:</strong><br>
1. Replace <code>assets/images/app_icon.png</code> with downloaded file<br>
2. Run: <code>flutter pub run flutter_launcher_icons</code><br>
3. Build: <code>flutter build apk --release</code>
</div>
</div>
<script>
const originalCanvas = document.getElementById('originalCanvas');
const adaptiveCanvas = document.getElementById('adaptiveCanvas');
const originalCtx = originalCanvas.getContext('2d');
const adaptiveCtx = adaptiveCanvas.getContext('2d');
let currentImage = null;
document.getElementById('imageInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
const img = new Image();
img.onload = function() {
currentImage = img;
drawIcons();
};
img.src = event.target.result;
};
reader.readAsDataURL(file);
}
});
function drawIcons() {
if (!currentImage) return;
// Clear canvases
originalCtx.clearRect(0, 0, 300, 300);
adaptiveCtx.clearRect(0, 0, 300, 300);
// Draw original
originalCtx.drawImage(currentImage, 0, 0, 300, 300);
// Draw adaptive with background
adaptiveCtx.fillStyle = '#1976D2';
adaptiveCtx.fillRect(0, 0, 300, 300);
// Draw icon at 66% size (centered)
const scaledSize = 300 * 0.66;
const offset = (300 - scaledSize) / 2;
adaptiveCtx.drawImage(currentImage, offset, offset, scaledSize, scaledSize);
}
function downloadIcon() {
if (!currentImage) {
alert('Please load an image first!');
return;
}
// Create high-res canvas for export (1024x1024)
const exportCanvas = document.createElement('canvas');
exportCanvas.width = 1024;
exportCanvas.height = 1024;
const ctx = exportCanvas.getContext('2d');
// Fill with transparent or background
ctx.fillStyle = 'transparent';
ctx.fillRect(0, 0, 1024, 1024);
// Draw icon at 66% size (safe zone)
const scaledSize = 1024 * 0.66;
const offset = (1024 - scaledSize) / 2;
ctx.drawImage(currentImage, offset, offset, scaledSize, scaledSize);
// Download
exportCanvas.toBlob(function(blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'app_icon_fixed.png';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
}
</script>
</body>
</html>