Skip to content

Commit 038964c

Browse files
authored
Create text_to_gif_pc.html
1 parent df4ea32 commit 038964c

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Text to GIF for WLED - Version 1.3</title>
5+
<style>
6+
#previewBox {
7+
border: 1px solid #000;
8+
padding: 10px;
9+
width: 300px;
10+
height: 50px;
11+
overflow: hidden;
12+
white-space: nowrap;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<h2>Text to GIF for WLED - Version 1.3</h2>
18+
<input type="text" id="textInput" placeholder="Enter text" oninput="updatePreview()">
19+
<p>Font Size: <span id="fontSizeValue">16</span>px</p>
20+
<input type="range" id="fontSizeSlider" min="8" max="32" value="16" oninput="updateFontSize()">
21+
<p>Font:
22+
<select id="fontSelect" onchange="updatePreview()">
23+
<option value="Arial">Arial</option>
24+
<option value="Courier New">Courier New</option>
25+
<option value="Georgia">Georgia</option>
26+
<option value="Times New Roman">Times New Roman</option>
27+
<option value="Verdana">Verdana</option>
28+
<option value="Gabriola">Gabriola</option>
29+
<option value="Impact">Impact</option>
30+
<option value="Tahoma">Tahoma</option>
31+
<option value="Andalus">Andalus</option>
32+
<option value="Arabic Typesetting">Arabic Typesetting</option>
33+
<option value="Comic Sans MS">Comic Sans MS</option>
34+
<option value="Ebrima">Ebrima</option>
35+
<option value="Consolas">Consolas</option>
36+
<option value="MS Serif">MS Serif</option>
37+
<option value="Symbol">Symbol</option>
38+
<option value="Yu Gothic">Yu Gothic</option>
39+
</select>
40+
</p>
41+
<p>Text Color:
42+
<input type="color" id="colorPicker" value="#FFFFFF" onchange="updatePreview()">
43+
</p>
44+
<p>Preview:</p>
45+
<div id="previewBox"></div>
46+
<button onclick="saveGIF()">Save</button>
47+
<p id="debugInfo"></p>
48+
49+
<script>
50+
function updateFontSize() {
51+
const fontSize = document.getElementById('fontSizeSlider').value;
52+
document.getElementById('fontSizeValue').textContent = fontSize;
53+
updatePreview();
54+
}
55+
56+
function updatePreview() {
57+
const text = document.getElementById('textInput').value;
58+
const fontSize = document.getElementById('fontSizeSlider').value;
59+
const font = document.getElementById('fontSelect').value;
60+
const color = document.getElementById('colorPicker').value;
61+
const previewBox = document.getElementById('previewBox');
62+
previewBox.style.font = `${fontSize}px ${font}`;
63+
previewBox.style.color = color;
64+
previewBox.textContent = text;
65+
}
66+
67+
function saveGIF() {
68+
const text = document.getElementById('textInput').value;
69+
const fontSize = document.getElementById('fontSizeSlider').value;
70+
const font = document.getElementById('fontSelect').value;
71+
const color = document.getElementById('colorPicker').value;
72+
73+
const canvas = document.createElement('canvas');
74+
canvas.width = 32;
75+
canvas.height = 16;
76+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
77+
ctx.font = `${fontSize}px ${font}`;
78+
ctx.fillStyle = color;
79+
80+
const textWidth = ctx.measureText(text).width;
81+
const frames = [];
82+
const totalFrames = Math.ceil(textWidth / canvas.width) * 32; // Adjust the total frames based on text width
83+
84+
for (let x = 0; x < totalFrames; x++) {
85+
ctx.clearRect(0, 0, canvas.width, canvas.height);
86+
ctx.fillText(text, -x, 12);
87+
frames.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
88+
}
89+
90+
const gif = new GIF({
91+
workers: 2,
92+
quality: 10,
93+
width: 32,
94+
height: 16,
95+
workerScript: 'gif.worker.js'
96+
});
97+
98+
frames.forEach(frame => {
99+
gif.addFrame(frame, { delay: 100 });
100+
});
101+
102+
gif.on('finished', function(blob) {
103+
const url = URL.createObjectURL(blob);
104+
const a = document.createElement('a');
105+
a.href = url;
106+
a.download = 'text.gif';
107+
a.click();
108+
});
109+
110+
gif.render();
111+
}
112+
</script>
113+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gif.js/0.2.0/gif.js"></script>
114+
</body>
115+
</html>

0 commit comments

Comments
 (0)