I have write some JavaScript and now I want to change the text
variable via php input. How can I do this? I hope there is any option to make it easy but right now I don't know anything about it.
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
var maxWidth = 252;
var lineHeight = 15;
var x = (canvas.width - maxWidth) / 2;
var y = 100;
var text = 'duuuuzo teeeekstuuu ksda sasdjk asjdk asjkdablsd ab dsjhabdsalkdbs adsj asbld';
function print(context, text, x, y, maxWidth, lineHeight) {
var words = text.split(' ');
var line = '';
words.forEach(function(word) {
var testLine = line + word + ' ';
var metrics = context.measureText(testLine);
var testWidth = metrics.width;
if (testWidth > maxWidth) {
context.fillText(line, x, y);
line = word + ' ';
y += lineHeight;
} else {
line = testLine;
}
});
context.fillText(line, x, y);
}
context.fillStyle = '#333';
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = '#fff';
context.font = '13px Arial, sans-serif';
print(context, text, x, y, maxWidth, lineHeight);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Generator</title>
</head>
<body>
<canvas width="272" height="340"></canvas>
<script src="js/index.js"></script>
</body>
</html>
Can someone help me with this?