<div>
<canvas id="myCanvas" width="500" height="300"></canvas>
  <img id="img1" alt="">
</div>
<button id="make">生成</button>
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");

var x = canvas.width/2;
var y = canvas.height/2;
context.font = "48px arial";
context.textAlign = "center";
        //context.fillText('Hello Cavans!!',x,y);
context.strokeStyle = "blue"; // stroke color
context.strokeText('Hello Cavans!!',x,y);

$("#make").click(function(){
  var myImg = document.querySelector("#img1");
  myImg.src = canvas.toDataURL("image/png");
})

     


External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js