mirror of
https://github.com/hexahigh/games.git
synced 2025-12-11 20:15:38 +01:00
update
This commit is contained in:
parent
88993eb955
commit
fdb1cd849c
@ -1,8 +1,12 @@
|
|||||||
<html>
|
<html>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" id="image-input" accept="image/*">
|
<input type="file" id="image-input" accept="image/*">
|
||||||
<img id="preview"></img>
|
<img id="preview"></img>
|
||||||
|
<button onclick="const img = document.getElementById('preview');
|
||||||
|
const blackAndWhiteImg = convertToBlackAndWhite(img);
|
||||||
|
">Black and white</button>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
let imgInput = document.getElementById('image-input');
|
let imgInput = document.getElementById('image-input');
|
||||||
@ -25,5 +29,27 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
function convertToBlackAndWhite(img) {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const imgData = ctx.getImageData(0, 0, img.width, img.height);
|
||||||
|
|
||||||
|
for (let i = 0; i < imgData.data.length; i += 4) {
|
||||||
|
let count = imgData.data[i] + imgData.data[i + 1] + imgData.data[i + 2];
|
||||||
|
let colour = 0;
|
||||||
|
if (count > 383) colour = 255;
|
||||||
|
imgData.data[i] = colour;
|
||||||
|
imgData.data[i + 1] = colour;
|
||||||
|
imgData.data[i + 2] = colour;
|
||||||
|
imgData.data[i + 3] = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.putImageData(imgData, 0, 0);
|
||||||
|
return canvas.toDataURL('image/png');
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user