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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
| <!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Générateur de texte</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="main.css" rel="stylesheet">
</head>
<style>
html, body {
width: 100%;
margin: 0 auto;
}
textarea, input, button, select {
border: 1px solid #FF4500;
}
.row {
width: 100%;
padding: 5px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
}
.column {
padding: 0px 10px;
display: flex;
flex-direction: column;
justify-content: center;
}
.input-container {
padding: 8px;
}
.titre {
font-size: 20px;
}
#text {
width: 200px;
height: 100px;
}
#download-link {
display: none;
}
#save-button {
font-size: 18px;
cursor: pointer;
margin: 20px;
color: white;
background-color: brown;
}
#save-button:hover {
color: brown;
background-color: orange;
}
#canvas {
max-width: 100%;
height: auto;
}
column
@media(max-width: 400px)
{.column
{text-align: center;
width: 100%;
padding-bottom: 10px;
}}
</style>
<body>
<div class="row">
<div class="col">
<div class="form-group">
<label for="text">
<center>Texte à insérer</center>
</label>
<div>
<textarea class="form-control" row="5" style="height: 130px;" id="text">
Votre texte
ou chiffres
ICI</textarea>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="font-size">
<center>Taille du texte</center>
</label>
<div class="input-container">
<input class="form-control" type="number" id="font-size" placeholder="eg: 50" value="80">
</div>
</div>
<div class="form-group">
<label for="gap-size">
<center>Espace entre les lignes</center>
</label>
<div class="input-container">
<input class="form-control" type="number" id="gap-size" placeholder="eg: 0" value="0">
</div>
</div>
<div class="form-group">
<label for="buffer-size">
<center>Distance depuis le haut</center>
</label>
<div class="input-container">
<input class="form-control" type="number" id="buffer-size" placeholder="e.g.: 200" value="140"/>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="font-style">
<center>Style d'écriture</center>
</label>
<div class="input-container">
<select id="font-style" class="form-control">
<option value="Times New Roman">Times New Roman</option>
<option value="Times">Times</option>
<option value="Arial">Arial</option>
<option value="Helvetica">Helvetica</option>
<option value="Courier New">Courier New</option>
<option value="Courier">Courier</option>
<option value="Verdana">Verdana</option>
<option value="Georgia">Georgia</option>
<option value="Palatino">Palatino</option>
<option value="Garamond">Garamond</option>
<option value="Bookman">Bookman</option>
<option value="Comic Sans MS">Comic Sans MS</option>
<option value="Trebuchet MS">Trebuchet MS</option>
<option value="Arial Black">Arial Black</option>
<option value="Impact">Impact</option>
</select>
</div>
</div>
<div class="form-group">
<div>
<label>
<center>Contour
<input class="checkbox" id="font-is-outline" type="checkbox"/></center>
</label>
</div>
</div>
<div class="form-group">
<div>
<label>
<center>Gras
<input class="checkbox" id="font-is-bold" type="checkbox"/></center>
</label>
</div>
</div>
</div>
<div class="col">
<div class="form-group mt-25">
<button id="save-button" class="btn btn-primary btn-lg"><center>Sauvegarder</center></button>
</div>
</div>
</div>
<div class="row">
<canvas id="canvas"></canvas>
</div>
<a id="download-link" download="https://pierres-info.fr/plaque/"></a>
<script>
const elmTextArea = document.getElementById("text");
const elmCanvas = document.getElementById("canvas");
const ctx = elmCanvas.getContext("2d");
const img = new Image();
function paint() {
elmCanvas.width = img.width;
elmCanvas.height = img.height;
ctx.drawImage(img, 0, 0);
const center = elmCanvas.width / 2;
const color = '#000000';
const fontSize = parseInt(document.getElementById("font-size").value);
const bufferSize = parseInt(document.getElementById("buffer-size").value);
const gapSize = parseInt(document.getElementById("gap-size").value);
const fontStyle = document.getElementById("font-style").value;
const fontIsOutline = document.getElementById("font-is-outline").checked;
const fontWeight = document.getElementById("font-is-bold").checked ? 'bold' : 'normal';
ctx.textAlign = "center";
ctx.font = `${fontWeight} ${fontSize}px ${fontStyle}`;
ctx.lineWidth = 1;
ctx.fillStyle = color;
ctx.strokeStyle = color;
elmTextArea.value.split('\n').forEach((line, i) => {
const yOffset = bufferSize + (i * (gapSize + fontSize));
if (fontIsOutline){
ctx.strokeText(line, center, yOffset);
} else {
ctx.fillText(line, center, yOffset);
}
});
}
img.onload = paint;
img.src = 'plaque.png';
document.addEventListener('input', e => {
if (e.target.matches('input,textarea')) {
e.stopPropagation();
paint();
}
});
document.addEventListener('change', e => {
if (e.target.matches('select,input[type=checkbox]')) {
e.stopPropagation();
paint();
}
});
document.getElementById('save-button').addEventListener('click', () => {
var dt = elmCanvas.toDataURL("image/png");
const elmDownload = document.getElementById("download-link");
elmDownload.href = dt;
elmDownload.click();
});
</script>
<style>@media (max-width: 420px) {html {margin-top: 0!important;}#wpadminbar{display:none;}}</style>
</body>
</html> |
Partager