javascript canvas 生成图片的方法
先生成base64格式的图片 然后ajax传到后台 写入服务器文件夹即可
<!DOCTYPE HTML>
<html><body>
<canvas id="myCanvas">
your browser does not support the canvas tag
</canvas>
<script type="text/javascript">
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FF0000';
ctx.fillRect(0, 0, 80, 100);var data = getBase64Image();
console.log(data);function getBase64Image() {
var canvas = document.getElementById('myCanvas');
var dataURL = canvas.toDataURL("image/png");
return dataURL
// return dataURL.replace("data:image/png;base64,", "");
}
</script>
</body></html>
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/18808.html