You can easily fix it.
you can use textBaseline = "middle"; and should use conversion to 50px top
means:
<canvas id="mainCanvas" width="320" height="240" style = "border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag. </canvas> <script> window.onload = function() { var canvas = document.getElementById("mainCanvas"); var ctx = canvas.getContext("2d"); ctx.textBaseline = "middle"; ctx.font = '100px Arial'; ctx.textAlign = 'left'; ctx.fillStyle = 'rgba(0, 0, 0, 1)'; ctx.save(); ctx.transform(1, 0, 0, 1, 0, 50); ctx.fillText('Test', 0, 0); ctx.restore(); } </script>
There is another error in your code: rgba (0, 0, 0, 255 ) the fourth number in rgba should be between 0-1, for example 0.75.
Why am I writing .save () and .restore ()? to reset convert and clear after use.
Of course you can use
ctx.fillText('Test', 0, 50);
Instead
ctx.save(); ctx.transform(1, 0, 0, 1, 0, 50); ctx.fillText('Test', 0, 0); ctx.restore();
source share