-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportPhotos.js
More file actions
67 lines (56 loc) · 1.82 KB
/
importPhotos.js
File metadata and controls
67 lines (56 loc) · 1.82 KB
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
/**
* @author Amy
*/
Storage.prototype.setObj = function(key, obj) {
return this.setItem(key, JSON.stringify(obj));
};
Storage.prototype.getObj = function(key) {
return JSON.parse(this.getItem(key));
};
function isLocalStorageSupported(){
if (typeof(Storage)!=="undefined" && window['localStorage' != null]){
return true;
} else {
return false;
}
}
function picChange(evt){
//bring selected photo in
//get files captured through input
var fileInput = evt.target.files;
//get the file
//window url
var windowURL = window.URL || window.webkitURL;
//picture url
var picURL= windowURL.createObjectURL(fileInput[0]);
//get canvas
var photoCanvas = document.getElementById('capturedPhoto');
var ctx = photoCanvas.getContext('2d');
//create image
var photo = new Image();
photo.onload=function(){
//draw photo into canvas when ready
ctx.drawImage(photo, 0, 0, 200, 200);
};
//load photo into canvas
photo.src=picURL;
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
//Handles grabbing the name of the file and then storing it in JSON
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push("<br>"+ f.name);
//add spacing for final CSV template
var fileName = JSON.stringify(f.name);
fileName = fileName.substring(0, fileName.length-1);
fileName = fileName.substring(1);
var titleName = JSON.stringify(f.name);
titleName = titleName.substring(0, titleName.length-5);
titleName = titleName.substring(1);
localStorage.setItem('fileName',fileName);
localStorage.setItem('title', titleName);
}
//document.getElementById('list').innerHTML = output.join('');
}