From 1f48f97af48fa1373d6435c197a0c757df09b09b Mon Sep 17 00:00:00 2001 From: awesomeuser Date: Fri, 4 Aug 2023 15:55:05 +0000 Subject: [PATCH] implement rudimetary canvas reading --- index.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 6f40a53..5a4185e 100644 --- a/index.php +++ b/index.php @@ -135,7 +135,17 @@ document.onmouseup = function() { drawing = false; // write image-bits for posting - bits.value = "101"; + let canvasData = canvas.getImageData(0, 0, 128, 64); + bits.value = ""; + + // not best method, ideally want to create an array and then merge + for (let i = 0; i < canvasData.data.length; i += 4) { + if (canvasData.data[i] == 0) { + bits.value += "1"; + } else { + bits.value += "0"; + } + } } canvas.onmousemove = function() {