Added styling and moved some stuff around

This commit is contained in:
Leon Mika 2025-09-12 21:51:43 +10:00
parent 66379af07a
commit 8dc2621f87
3 changed files with 100 additions and 56 deletions

54
freelens-logo/index.html Normal file
View file

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
<title>Freelens Logo</title>
<title>Tools</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
>
<style>
canvas {
border: 1px solid #ccc;
display: block;
margin-bottom: 10px;
}
</style>
</head>
<body class="container">
<header>
<hgroup>
<h1>Freelens Logo Creator</h1>
<p>Create logos for K8S clusters in Freelens</p>
</hgroup>
</header>
<main class="grid">
<div>
<form id="logoForm">
<input type="text" id="upperText" name="Upper" placeholder="Upper">
<input type="text" id="lowerText" name="Lower" placeholder="Lower">
<label>Background:
<select id="bgColor" name="Background">
<option value="#cd2d2d">Red</option>
<option value="#d26800">Orange</option>
<option value="#f39c12">Amber</option>
<option value="#27ae60">Green</option>
<option value="#17a094">Teal</option>
<option value="#2980b9">Blue</option>
<option value="#8e44ad">Purple</option>
<option value="#7f8c8d">Gray</option>
</select>
</label>
</form>
</div>
<div>
<canvas id="logoCanvas" width="100" height="100"></canvas>
<button id="downloadBtn">Download PNG</button>
</div>
</main>
<script src="script.js"></script>
</body>
</html>

View file

@ -27,13 +27,18 @@
ctx.fillStyle = colorSelect.value; ctx.fillStyle = colorSelect.value;
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = 'white'; const upper = upperInput.value;
ctx.lineWidth = LINE_WIDTH; const lower = lowerInput.value;
const yLine = height / 2;
ctx.beginPath(); if (lower != "") {
ctx.moveTo(PADDING, yLine); ctx.strokeStyle = 'white';
ctx.lineTo(width - PADDING, yLine); ctx.lineWidth = LINE_WIDTH;
ctx.stroke(); const yLine = height / 2;
ctx.beginPath();
ctx.moveTo(PADDING, yLine);
ctx.lineTo(width - PADDING, yLine);
ctx.stroke();
}
const availableWidth = width - PADDING * 2; const availableWidth = width - PADDING * 2;
const availableHeight = height - PADDING * 2; const availableHeight = height - PADDING * 2;
@ -43,15 +48,19 @@
ctx.textAlign = 'center'; ctx.textAlign = 'center';
ctx.textBaseline = 'middle'; ctx.textBaseline = 'middle';
const upper = upperInput.value.toUpperCase(); if (lower != "") {
let fontSize = fitText(upper, availableWidth, halfHeight); let fontSize = fitText(upper, availableWidth, halfHeight);
ctx.font = `bold ${fontSize}px sans-serif`; ctx.font = `bold ${fontSize}px sans-serif`;
ctx.fillText(upper, width / 2, PADDING + halfHeight / 2); ctx.fillText(upper, width / 2, PADDING + halfHeight / 2);
const lower = lowerInput.value.toUpperCase(); fontSize = fitText(lower, availableWidth, halfHeight);
fontSize = fitText(lower, availableWidth, halfHeight); ctx.font = `bold ${fontSize}px sans-serif`;
ctx.font = `bold ${fontSize}px sans-serif`; ctx.fillText(lower, width / 2, height - PADDING - halfHeight / 2 + 4);
ctx.fillText(lower, width / 2, height - PADDING - halfHeight / 2); } else {
let fontSize = fitText(upper, availableWidth, halfHeight);
ctx.font = `bold ${fontSize}px sans-serif`;
ctx.fillText(upper, width / 2, height / 2);
}
} }
upperInput.addEventListener('input', draw); upperInput.addEventListener('input', draw);

View file

@ -1,45 +1,26 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="utf-8">
<title>Canvas Logo Generator</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<style> <meta name="color-scheme" content="light dark">
body { <title>Tools</title>
font-family: sans-serif; <link
padding: 20px; rel="stylesheet"
background: #f0f0f0; href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
} >
form {
margin-bottom: 10px;
}
canvas {
border: 1px solid #ccc;
display: block;
margin-bottom: 10px;
}
</style>
</head> </head>
<body> <body class="container">
<form id="logoForm"> <header>
<label>Upper: <input type="text" id="upperText" name="Upper"></label> <hgroup>
<label>Lower: <input type="text" id="lowerText" name="Lower"></label> <h1>Tools</h1>
<label>Background: <p>Collection of online tools</p>
<select id="bgColor" name="Background"> </hgroup>
<option value="#c0392b">Red</option> </header>
<option value="#d35400">Orange</option> <main>
<option value="#f39c12">Amber</option> <ul>
<option value="#27ae60">Green</option> <li><a href="/freelens-logo/">Freelens Logo maker</a></li>
<option value="#16a085">Teal</option> </ul>
<option value="#2980b9">Blue</option> </main>
<option value="#8e44ad">Purple</option>
<option value="#7f8c8d">Gray</option>
</select>
</label>
</form>
<canvas id="logoCanvas" width="80" height="80"></canvas>
<button id="downloadBtn">Download PNG</button>
<script src="script.js"></script>
</body> </body>
</html> </html>