js实现html页面转图片,并保存图片在本地,实现原理为(html转canvas、canvas转image)
需要的库:canvas2image.js
下载地址:https://github.com/SuperAL/canvas2image;
需要的库:html2canvas.js
下载地址:http://html2canvas.hertzen.com/dist/html2canvas.min.js
效果如下:
首先是html页面:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=320,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>实现HTML转图片</title>
<style type="text/css" media="screen">
.bg{
width: 100%;
min-height: 100%;
height: 100vh;
background-color: #a799ac;
text-align: center;
}
.text{
width: 50%;
margin-top: 20%;
height: 25px;
border: 1px solid #b7c092;
border-radius: 10px;
outline: none;
}
.save, .picture{
border-radius: 10px;
border: none;
width: 60px;
padding: 0;
height: 25px;
background: #9cd8b1;
outline: none;
}