-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.html
68 lines (60 loc) · 3.78 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<img src="http://img2.imgtn.bdimg.com/it/u=1448077422,73818242&fm=206&gp=0.jpg" id="t1"/>
<button id="down">asd</button>
<button id="down2">agsa</button>
<script type="text/javascript" src="lib/zip/zip.js"></script>
<script type="text/javascript" src="lib/zip/zip-fs.js"></script>
<script>
function saveFile(data, filename){
var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
save_link.href = data;
save_link.download = filename;
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
save_link.dispatchEvent(event);
};
var _fixType = function(type) {
type = type.toLowerCase().replace(/jpg/i, 'jpeg');
var r = type.match(/png|jpeg|bmp|gif/)[0];
return 'image/' + r;
};
zip.useWebWorkers = true;
zip.workerScriptsPath = './lib/zip/';
var zipFs = new zip.fs.FS();
//var img=document.getElementById("t1");
var img=new Image();
//img.setAttribute('crossOrigin', 'anonymous');
img.crossOrigin = "*"
img.src="http://img2.imgtn.bdimg.com/it/u=1448077422,73818242&fm=206&gp=0.jpg";
var canvas,imgData;
img.onload=function(arg1,arg2){
canvas= document.createElement("canvas");
//document.body.appendChild(canvas)
canvas.height = img.height;
canvas.width = img.width;
var context=canvas.getContext("2d");
context.drawImage(img,0,0);
imgData = canvas.toDataURL("jpg");
imgData = imgData.replace(_fixType("jpg"),'image/octet-stream');//base64
zipFs.root.addData64URI("aaa.txt", "data:text/plain;base64,TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldH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BzYWVwaXVzLiBDbGFyaXRhcyBlc3QgZXRpYW0gcHJvY2Vzc3VzIGR5bmFtaWN1cywgcXVpIHNlcXVpdHVyIG11dGF0aW9uZW0gY29uc3VldHVkaXVtIGxlY3RvcnVtLiBNaXJ1bSBlc3Qgbm90YXJlIHF1YW0gbGl0dGVyYSBnb3RoaWNhLCBxdWFtIG51bmMgcHV0YW11cyBwYXJ1bSBjbGFyYW0sIGFudGVwb3N1ZXJpdCBsaXR0ZXJhcnVtIGZvcm1hcyBodW1hbml0YXRpcyBwZXIgc2VhY3VsYSBxdWFydGEgZGVjaW1hIGV0IHF1aW50YSBkZWNpbWEuIEVvZGVtIG1vZG8gdHlwaSwgcXVpIG51bmMgbm9iaXMgdmlkZW50dXIgcGFydW0gY2xhcmksIGZpYW50IHNvbGxlbW5lcyBpbiBmdXR1cnVtLg==");
}
document.getElementById("down").addEventListener("click",function(){
saveFile(imgData,"test_"+new Date().getTime()+"."+"jpg");
});
var zipFs = new zip.fs.FS();
document.getElementById("down2").addEventListener("click",function(){
zipFs.exportData64URI(function(zippedDataURI){
saveFile(zippedDataURI,"0.zip");
},function(){},function(){
debugger;
})
});
</script>
</body>
</html>