How to center text drawing on the canvas in JavaScript

1 Answer

0 votes
<canvas id="canvas" width="1024" height="768"></canvas>
<script type="text/JavaScript">   

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

ctx.font = "36px serif";
ctx.fillStyle = "Green";
ctx.textAlign = "center";
ctx.fillText("PHP Programming", canvas.width/2, canvas.height/2); 

/*
run:  
  
   
*/
  
</script>

 



answered May 25, 2016 by avibootz

Related questions

1 answer 221 views
2 answers 237 views
1 answer 395 views
1 answer 192 views
...