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

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

View file

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