-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (74 loc) · 2.5 KB
/
index.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
document.addEventListener("DOMContentLoaded", function () {
const brightnessSlider = document.getElementById("brightnessSlider");
const contrastSlider = document.getElementById("contrastSlider");
const dropArea = document.getElementById("dropArea");
const exportBtn = document.getElementById("export");
// Initial brightness and contrast values
let brightnessValue = 100;
let contrastValue = 100;
// Update the image style when sliders are changed
brightnessSlider.addEventListener("input", function () {
brightnessValue = this.value;
updateImageStyle();
});
contrastSlider.addEventListener("input", function () {
contrastValue = this.value;
updateImageStyle();
});
// Function to update image style with current brightness and contrast values
function updateImageStyle() {
dropArea.style.filter = `brightness(${brightnessValue}%) contrast(${contrastValue}%)`;
}
});
// Prevent default behavior when dragging files over the drop area
dropArea.addEventListener("dragover", (e) => {
e.preventDefault();
dropArea.style.backgroundColor = "#777";
});
// Restore background color when dragging leaves the drop area
dropArea.addEventListener("dragleave", () => {
dropArea.style.backgroundColor = "transparent";
});
// Handle dropped files
dropArea.addEventListener("drop", (e) => {
e.preventDefault();
dropArea.style.backgroundColor = "transparent";
const file = e.dataTransfer.files[0];
console.log(file);
displayImage(file);
});
fileInput.addEventListener("change", () => {
const file = fileInput.files[0];
displayImage(file);
});
var imageURL;
// Function to display the selected image
function displayImage(file) {
const reader = new FileReader();
reader.onload = (event) => {
// editedImage.src = event.target.result;
// editedImage.style.display = "block";
imageURL = event.target.result;
dropArea.style.backgroundImage = `url('${imageURL}')`;
};
reader.readAsDataURL(file);
dropArea.style.backgroundImage = `url(${reader.result})`;
}
function processImage() {
var fileInput = document.getElementById("fileInput");
var file = fileInput.files[0];
var formData = new FormData();
formData.append("file", file);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log("File uploaded successfully!");
} else {
console.log("Error uploading file.");
}
}
};
xhr.open("POST", "upload.php", true);
xhr.send(formData);
}