-
Notifications
You must be signed in to change notification settings - Fork 2
/
Product.js
46 lines (41 loc) · 1.27 KB
/
Product.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
const apiURL = 'https://quickchart.io/watermark';
const markedIMG = 'https://static.vecteezy.com/system/resources/thumbnails/017/785/303/small/creative-wrong-icon-3d-render-png.png'
class Product {
constructor() {
this.div;
this.imageHTMLElement;
this.rawImageLink;
this.processedImage;
}
async processImage() {
const params = {
mainImageUrl: this.rawImageLink,
markImageUrl: markedIMG,
position: 'center',
opacity: 0.8,
markRatio: 1.0,
};
fetch(apiURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
})
.then((response) => {
const contentType = response.headers.get('Content-Type');
return response.blob();
})
.then((data) => {
if (data instanceof Blob) {
const imageUrl = URL.createObjectURL(data);
this.processedImage = imageUrl;
} else {
console.error('error from API:', data);
}
})
.catch((error) => {
console.error('error creating overlay:', error);
});
}
}