VulpesOS/gaia/apps/gallery/test/images/creator.html
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

60 lines
1.5 KiB
HTML
Executable file

<style>
body, textarea {
font-size: 24px;
}
</style>
<script>
function create() {
var text = document.getElementById('text').value;
var lines = text.split('\n');
var width = parseInt(document.getElementById('width').value);
var height = parseInt(document.getElementById('height').value);
var background = document.getElementById('background').value
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
var context = canvas.getContext('2d');
var fontSize = Math.round(height / (lines.length * 2));
context.font = fontSize + 'px sans-serif';
if (background) {
context.fillStyle = background;
context.fillRect(0, 0, width, height);
}
context.fillStyle = '#000';
// context.strokeStyle = '#fff';
context.lineWidth = 2;
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
var lineWidth = context.measureText(line).width;
context.fillText(line,
(width - lineWidth)/2,
height * .33 + i * 1.1 * fontSize);
/*
context.strokeText(line,
(width - lineWidth)/2,
height * .33 + i * 1.1 * fontSize);
*/
}
canvas.toBlob(function(blob) {
var url = URL.createObjectURL(blob);
document.getElementById('output').src = url;
});
}
</script>
<br><textarea id="text" rows=4 cols=40></textarea>
<br>width: <input id="width">
<br>height: <input id="height">
<br>background: <input id="background">
<br><button onclick="create()">Create</button>
<br><img id="output">