-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage2b64.html
More file actions
70 lines (66 loc) · 2.4 KB
/
image2b64.html
File metadata and controls
70 lines (66 loc) · 2.4 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Resizer and Base64 Exporter</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
canvas {
border: 1px solid #ccc;
margin: 20px 0;
}
button, input {
margin: 10px;
}
</style>
</head>
<body>
<h1>Charger et Redimensionner Image</h1>
<input type="file" id="imageInput" accept="image/*">
<canvas id="canvas" width="256" height="256"></canvas>
<button id="exportBtn" disabled>Exporter Base64 vers image_B64.txt</button>
<script>
const imageInput = document.getElementById('imageInput');
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const exportBtn = document.getElementById('exportBtn');
imageInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
// Redimensionner l'image à 256x256
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0, 256, 256);
exportBtn.disabled = false;
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
});
exportBtn.addEventListener('click', () => {
// Exporter en base64
const base64 = canvas.toDataURL('image/jpeg'); // Ou 'image/png' si préféré
const blob = new Blob([base64], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'image_B64.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
</script>
</body>
</html>