From b309653a391ed9eb8ef7605c5b689f650b1232d3 Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Mon, 9 Nov 2015 17:08:24 +0000 Subject: [PATCH] (#2) Make the QR code center aligned --- qr.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qr.js b/qr.js index 4f127e6..c8a0955 100644 --- a/qr.js +++ b/qr.js @@ -1045,10 +1045,12 @@ px /= width; px = Math.floor(px); + var offset = Math.floor((size - (px * width)) / 2); + // Draw the QR code. c2d.clearRect(0, 0, size, size); c2d.fillStyle = data.background || '#fff'; - c2d.fillRect(0, 0, px * (width + 8), px * (width + 8)); + c2d.fillRect(0, 0, size, size); c2d.fillStyle = data.foreground || '#000'; var i, j; @@ -1056,7 +1058,7 @@ for (i = 0; i < width; i++) { for (j = 0; j < width; j++) { if (frame[j * width + i]) { - c2d.fillRect(px * i, px * j, px, px); + c2d.fillRect(px * i + offset, px * j + offset, px, px); } } }