-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (26 loc) · 1.08 KB
/
Copy pathscript.js
File metadata and controls
32 lines (26 loc) · 1.08 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
async function processImage() {
const fileInput = document.getElementById('fileInput');
const colorCountInput = document.getElementById('colorCount').value;
const dimensionInput = document.getElementById('dimension').value;
const formData = new FormData();
formData.append('image', fileInput.files[0]);
formData.append('colorCount', colorCountInput);
formData.append('dimension', dimensionInput);
const response = await fetch('http://localhost:3000/processImage', {
method: 'POST',
body: formData,
});
const result = await response.json();
// Display color palette
const paletteDiv = document.getElementsByClassName('palette')[0];
paletteDiv.innerHTML = '';
result.colors.forEach((color) => {
const colorDiv = document.createElement('div');
colorDiv.className = 'color-box'
colorDiv.style.backgroundColor = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
paletteDiv.appendChild(colorDiv);
});
// Display the new image
const newImageElement = document.getElementById('newImage');
newImageElement.src = `data:image/png;base64,${result.newImage}`;
}