HTML 转 canvas 转 image
作者:chrispy
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="j.js"></script>
<script src="html2canvas.js"></script>
</head>
<body>
<div id="capture" style="padding: 10px; background: #f5da55">
<h4 style="color: #000; ">Hello world!</h4>
</div>
<div></div>
<script>
$(function () {
html2canvas(document.querySelector("#capture")).then(function (canvas) {
convertImageToCanvas(canvas)
});
})
function convertImageToCanvas(canvas) {
var image = new Image();
image.src = canvas.toDataURL("image/png");
$('.imgblock').html(image)
return image;
}
</script>
</body>
</html>