-
Notifications
You must be signed in to change notification settings - Fork 0
/
img.js
29 lines (25 loc) · 911 Bytes
/
img.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
let photoDiv = document.querySelector("#photo");
let photoUploadInput = document.querySelector("#photo-upload");
let downloadDiv = document.querySelector("#download");
photoDiv.addEventListener("click", function () {
photoUploadInput.click();
});
photoUploadInput.addEventListener("change", function (event) {
console.log(event);
let fileObj = event.target.files[0];
console.log(fileObj);
let filePath = URL.createObjectURL(fileObj, { type: "image/jpg" });
let img = document.createElement("img");
img.setAttribute("src", filePath);
img.classList.add("sticky-image");
addSticky(img);
});
downloadDiv.addEventListener("click" , function(){
let imagePath = canvas.toDataURL("image/jpg");
console.log(imagePath);
// <a href="" download="canvas.jpg"></a>
let aTag = document.createElement("a");
aTag.download = "canvas.jpg";
aTag.href = imagePath;
aTag.click();
})