-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
42 lines (31 loc) · 1.18 KB
/
script.js
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
Window.onload = function(event){
console.log('loading..');
var imageLoader = document.getElementById('img_capture');
imageLoader.addEventListener('change', handleImage, false);
var canvas = document.getElementById('img_canvas');
var ctx = canvas.getContext('2d');
function handleImage(e){
var reader = new FileReader();
reader.onload = function(event){
var img = new Image();
img.onload = function(){
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img,0,0);
//landscape
if(img.width>img.height){
$(canvas).removeClass('portrait').addClass('landscape');
}else{
$(canvas).removeClass('landscape').addClass('portrait');
}
}
img.src = event.target.result;
}
reader.readAsDataURL(e.target.files[0]);
}
function download() {
var dt = canvas.toDataURL();
this.href = dt; //this may not work in the future..
}
document.getElementById('download').addEventListener('click', download, false);
}();