-
Notifications
You must be signed in to change notification settings - Fork 0
/
texto copy.html
144 lines (124 loc) · 4.86 KB
/
texto copy.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html>
<head>
<title>Image Alphabet Phrase</title>
<style>
.letter-image {
display: inline-block;
width: 100px;
height: 100px;
object-fit: contain;
}
.shifted {
text-transform: uppercase;
}
.blank-box {
display: inline-block;
width: 50px;
height: 50px;
background-color: #cccccc00;
margin: 10px;
}
.bordered-phrase {
border: 2px solid black;
padding: 50px;
margin-top: 50px;
}
</style>
</head>
<body>
<div>
<label for="phrase-input">Enter something here (use only a-z without accents):</label>
<textarea id="phrase-input" rows="5" oninput="displayPhraseAsImages()"></textarea>
</div>
<div class="bordered-phrase" id="bordered-phrase-container"></div>
<div style="position: absolute; bottom: 30px; right: 30px;">builtbygus.com</div>
<br>
<button class="save-button">Save phrase as image</button>
<script src="html2canvas.min.js"></script>
<script>
var imagePath = '';
var letterImages = {
'a': 'a.jpg',
'b': 'b.jpg',
'c': 'c.jpg',
'd': 'd.jpg',
'e': 'e.jpg',
'f': 'f.jpg',
'g': 'g.jpg',
'h': 'h.jpg',
'i': 'i.jpg',
'j': 'j.jpg',
'k': 'k.jpg',
'l': 'l.jpg',
'm': 'm.jpg',
'n': 'n.jpg',
'o': 'o.jpg',
'p': 'p.jpg',
'q': 'q.jpg',
'r': 'r.jpg',
's': 's.jpg',
't': 't.jpg',
'u': 'u.jpg',
'v': 'v.jpg',
'w': 'w.jpg',
'x': 'x.jpg',
'y': 'y.jpg',
'z': 'z.jpg'
};
function displayPhraseAsImages() {
var phraseInput = document.getElementById('phrase-input').value;
var borderedPhraseContainer = document.getElementById('bordered-phrase-container');
borderedPhraseContainer.innerHTML = ''; // Clear any previous content
var lines = phraseInput.split('\n');
for (var j = 0; j < lines.length; j++) {
var line = lines[j];
var lineContainer = document.createElement('div');
lineContainer.classList.add('line-container');
for (var i = 0; i < line.length; i++) {
var letter = line[i].toLowerCase();
if (letter in letterImages) {
var imageFilename = imagePath + letterImages[letter];
var imageElement = document.createElement('img');
imageElement.src = imageFilename;
imageElement.alt = letter;
imageElement.classList.add('letter-image');
lineContainer.appendChild(imageElement);
} else if (letter === ' ') {
var blankBox = document.createElement('div');
blankBox.classList.add('blank-box');
lineContainer.appendChild(blankBox);
} else {
console.warn('No image found for letter ' + letter);
}
}
borderedPhraseContainer.appendChild(lineContainer);
}
}
function saveAsImage() {
var borderedPhrase = document.querySelector('.bordered-phrase');
// Use html2canvas library to capture the borderedPhrase container as an image
html2canvas(borderedPhrase).then(function(canvas) {
var ctx = canvas.getContext('2d');
// Add the watermark text to the canvas
var watermarkText = 'builtbygus.com';
ctx.fillStyle = 'black';
ctx.font = '12px Arial';
ctx.fillText(watermarkText, canvas.width - 110, canvas.height - 10);
// Convert the canvas to a data URL
var dataURL = canvas.toDataURL('image/png');
// Create a temporary link element
var downloadLink = document.createElement('a');
downloadLink.href = dataURL;
downloadLink.download = 'phrase.png';
// Programmatically trigger the click event to download the image
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
});
}
var button = document.querySelector('.save-button');
button.addEventListener('click', saveAsImage);
</script>
</body>
</html>