canvas-text-als-bild-ausgeben.php


Quell Code


<html>

<head>

<style>
canvas {
    background: white;
	border: 1px solid #333;
}

</style>
</head>
<body>





<h1>Text mit canvas</h1>
<main>
	<canvas id="canvas" width="400" height="250">Beispiel für einen Text "Hello World!" mit Canvas.</canvas>
</main>
<script>

	function zeichne() {
		var element = document.getElementById('canvas');
    console.log(element);
		if (element.getContext) {
			var context = element.getContext('2d'),
				text = 'Hallöle Welt!';
			context.clearRect(0, 0, element.width, element.height);
			context.fillStyle = 'lightyellow';
			context.strokeStyle = 'brown';
			context.font = '60px Arial';
			context.textAlign = 'center';
			context.textBaseline = 'middle';
			context.fillText(text, element.width / 2, element.height / 2);
			context.strokeText(text, element.width / 2, element.height / 2);
		}
	}
zeichne();
	

</script>
</body>
</html>


Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0