-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
32 lines (27 loc) · 1017 Bytes
/
index.html
File metadata and controls
32 lines (27 loc) · 1017 Bytes
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
Hello World!
<input type="file" id="upload" accept="image/jpeg, image/png">
<canvas id="canvas"></canvas>
<a id="downloadLink" download="converted-image.png">Download Converted Image</a>
<script>
document.getElementById('upload').addEventListener('change', handleImageUpload);
function handleImageUpload(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const dataURL = canvas.toDataURL('image/png');
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = dataURL;
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
</script>