-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvasImage.js
97 lines (81 loc) · 2.42 KB
/
canvasImage.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class CanvasImage {
constructor() {
this.img = null;
let input;
this.editBtn = null;
this.editMode = false;
const getLastItem = (thePath) =>
thePath.substring(thePath.lastIndexOf("/") + 1);
let path = getLastItem(window.location.pathname);
console.log( path, path.length, "hey path", );
const notApp = ["index", "index.html", "pic", "pic.html"]
if ((path.length && !notApp.includes(path)) ) {
AppMode = select("#AppOpt");
SaveWithoutAsync = true;
loadImage(appPic, (img) => {
resizeCanvas(img.width, img.height);
image(img, 0, 0, img.width, img.height);
});
AppMode.elt.getElementsByTagName("input").forEach((v) => {
const id = v.id;
select("#" + id).input((f) => {
actions[id](f);
});
});
AppMode.elt.getElementsByTagName("button").forEach((v) => {
const id = v.id;
select("#" + id).mousePressed(actions[id]);
});
}
//Canvas Image Set An Image As Background of the canvas.
//It also set the width and height of the canvas approximately to the image size
//handleFile
input = createFileInput((file) => {
if (file.type === "image") {
loadImage(
file.data,
(img) => {
resizeCanvas(img.width * 2, img.height * 2);
image(img, 20, 20, width - 30, height - 30);
this.img = img;
this.handleEdit();
},
(e) => {
alert("Unable To Load Image");
}
);
} else {
alert("Please Select An Image");
this.img = null;
}
});
input.attribute("accept", "image/*");
input.attribute("id", "img");
input.parent("#initOpt");
if (AppMode) {
input.hide();
}
}
//Apply filter to the image when edit button is pressed
handleEdit() {
if (this.img) {
this.editBtn = createButton("Blur Image");
this.editBtn.parent("#initOpt");
}
this.editBtn.mousePressed(() => {
if (!this.editMode) {
helpers.getPixels();
loadPixels();
noFill();
this.img.filter(BLUR, 3);
image(this.img, 20, 20, width - 30, height - 30);
this.editBtn.attribute("disabled", "");
this.editMode = true;
} else {
image(this.img, 20, 20, width - 30, height - 30);
this.editBtn.html("Blur Image");
this.editMode = false;
}
});
}
}