-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfonks.js
183 lines (171 loc) · 4.34 KB
/
fonks.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var loadingAnim;
var angularSpeed = 8;
var latestPrompt = "";
loadingAnim = new Konva.Animation(function (frame) {
let currentSWidth = controller.strokeWidth();
var angleDiff = angularSpeed * (frame.timeDiff / 1000);
if (currentSWidth >= 7) {
angularSpeed = -8;
} else if (currentSWidth <= 2) {
angularSpeed = 8;
}
controller.strokeWidth(currentSWidth + angleDiff);
}, layer);
function predict(options) {
changeDraggable(false);
$("#save").slideDown("slow");
let prompt = options.prompt || "fatih sultan mehmet",
sampler = options.sampler || "Euler a",
steps = options.steps || 10,
seed = options.seed || -1,
w = options.w || 512,
h = options.h || 512,
tiling = options.tiling || false;
latestPrompt = prompt;
$.ajax({
url: "http://127.0.0.1:3000/txt2img",
type: "POST",
data: JSON.stringify({
prompt,
steps,
sampler_name: sampler,
seed,
width: w,
height: h,
tiling,
}),
contentType: "application/json",
complete: (res) => {
let placeX = controller.attrs.x,
placeY = controller.attrs.y;
let result = res.responseJSON;
let firstimage = result.image;
var imageObj1 = new Image();
imageObj1.src = "data:image/png;base64," + firstimage;
// darth vader
let newImage = new Konva.Image({
width: 512,
height: 512,
x: placeX,
y: placeY,
image: imageObj1,
});
newImage.off("click");
layer.add(newImage);
let zIndex = controller.zIndex();
controller.zIndex(zIndex + 2);
changeDraggable(true);
},
});
}
var outPaintImgs = [];
var currIdx = 0;
function outpaint(options) {
changeDraggable(false);
let prompt = options.prompt || "fatih sultan mehmet",
image = options.image;
latestPrompt = prompt;
$.ajax({
url: "http://127.0.0.1:3000/outpaint",
type: "POST",
data: JSON.stringify({
prompt,
image,
}),
contentType: "application/json",
complete: (res) => {
let result = res.responseJSON;
result.images.shift();
outPaintImgs = [];
currIdx = 0;
result.images.forEach((image) => {
let imObj = new Image();
imObj.src = "data:image/png;base64," + image;
outPaintImgs.push(imObj);
});
controller.fillPatternImage(outPaintImgs[currIdx]);
loadingAnim.stop();
$("#selector").slideDown("slow");
$("#currentIndex").text(currIdx + 1);
//layer.add(newImage);
},
});
}
function changeDraggable(can) {
if (!can) {
loadingAnim.start();
} else {
controller.strokeWidth(1);
loadingAnim.stop();
}
controller.draggable(can);
}
function loadingSequence() {
for (let st = 0; st < 20; st += 0.05) {
console.log(st);
setTimeout(() => {
controller.strokeWidth(21 - st);
}, st * 230);
}
}
$("#previousImg").click(() => {
if (currIdx > 0) {
currIdx--;
}
$("#currentIndex").text(currIdx + 1);
controller.fillPatternImage(outPaintImgs[currIdx]);
});
$("#nextImg").click(() => {
if (currIdx < outPaintImgs.length - 1) {
currIdx++;
}
$("#currentIndex").text(currIdx + 1);
controller.fillPatternImage(outPaintImgs[currIdx]);
});
$("#btnAccept").click(() => {
let placeX = controller.attrs.x,
placeY = controller.attrs.y;
let newImage = new Konva.Image({
width: 512,
height: 512,
x: placeX,
y: placeY,
image: outPaintImgs[currIdx],
});
controller.fillPatternImage(null);
changeDraggable(true);
layer.add(newImage);
let zIndex = controller.zIndex();
controller.zIndex(zIndex + 1);
$("#selector").slideUp("slow");
});
$("#btnCancel").click(() => {
controller.fillPatternImage(null);
changeDraggable(true);
$("#selector").slideUp("slow");
});
$("#save").click(function () {
let oldScale = stage.scale();
stage.scale({ x: 1, y: 1 });
controller.visible(false);
bgLayer.visible(false);
bdImage.visible(false);
var image = stage.toImage({
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY,
pixelRatio: 1,
callback(img) {
let base64 = img.src.split(",")[1];
var download = document.createElement("a");
download.href = img.src;
download.download = latestPrompt + ".png";
download.click();
},
});
controller.visible(true);
bgLayer.visible(true);
bdImage.visible(true);
stage.scale(oldScale);
});