canvas保存图片

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>初学html5</title>
<meta name="keywords" content="">
<meta name="description" content="">
<script src="canva5.js"></script>
<style>
*{margin:0;padding:0;}
</style>
</head>
<body onload="draw('canvas');">
<canvas id="canvas" width="400" height="300"></canvas>
</body>
</html>

function draw(id)
{
var canvas=document.getElementById(id);
var context=canvas.getContext('2d');

context.fillStyle='green';
context.fillRect(0,0,800,300);
context.fillStyle="#fff";
context.strokeStyle="#fff";
context.font="bold 40px 宋体";
context.textBaseline="top";
context.fillText("麦子学院",0,0);
context.strokeText("麦子学院",0,40);

window.location=canvas.toDataURL("images/jpeg");

}

原文地址:https://www.cnblogs.com/ll-taj/p/5293033.html