运用canvas将两张图片img1,img2画在一起,生成一张新的图片img3,然后实现点击下载图片img3
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<img src="1.png" id="img1" style="display: block" width="240" height="240"/>
<img src="2.png" id="img2" style="display: block" width="500" height="750"/>
<img id="img3" />
<button onclick="draw()" id="btn">点击下载</button>
<script>
function draw() {
var img1 = document.getElementById("img1"),
img2 = document.getElementById("img2"),
img3 = document.getElementById("img3");
img1.width=240;