From b3565df79fb8c287101a8cb105d0726c6595b68e Mon Sep 17 00:00:00 2001 From: whoisnian Date: Fri, 20 Jul 2018 00:20:26 +0800 Subject: [PATCH] fixed the error when convert image into codes in vertical mode --- index.html | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 69c6769..fff9722 100644 --- a/index.html +++ b/index.html @@ -668,18 +668,22 @@ var w = document.createElement("input"); w.type = "number"; w.name = "width"; + w.id = "screenWidth"; w.min = 0; w.className = "size-input"; w.value = img.width; - w.oninput = function() { canvas.width = this.value; update(); }; + settings["screenWidth"] = img.width; + w.oninput = function() { canvas.width = this.value; update(); updateInteger('screenWidth'); }; var h = document.createElement("input"); h.type = "number"; h.name = "height"; + h.id = "screenHeight"; h.min = 0; h.className = "size-input"; h.value = img.height; - h.oninput = function() { canvas.height = this.value; update(); }; + settings["screenHeight"] = img.height; + h.oninput = function() { canvas.height = this.value; update(); updateInteger('screenHeight'); }; var gil = document.createElement("span"); gil.innerHTML = "glyph"; @@ -796,7 +800,6 @@ // Output the image as a string for vertically drawing displays function imageToStringVertical(image){ - var page = 0; var ctx = image.ctx; var canvas = image.canvas; @@ -807,12 +810,12 @@ var output_index = 0; for(var p=0; p < Math.ceil(settings["screenHeight"] / 8); p++){ - for(var x = 0; x <= settings["screenWidth"]; x++){ + for(var x = 0; x < settings["screenWidth"]; x++){ var byteIndex = 7; var number = 0; for (var y = 7; y >= 0; y--){ - var index = ((p*8)+y)*(settings["screenWidth"]*4)+x; + var index = ((p*8)+y)*(settings["screenWidth"]*4)+x*4; var avg = (data[index] + data[index +1] + data[index +2]) / 3; if (avg > settings["threshold"]){ number += Math.pow(2, byteIndex);