neocotic / qrious

Pure JavaScript library for QR code generation using canvas
https://neocotic.com/qrious
Other
1.55k stars 215 forks source link

Center the QR code, solution #111

Open runplay opened 6 years ago

runplay commented 6 years ago

Hi, did post this before but to a closed one #2

As wanted to use the library, I have made a tweak to fix the issue this just one line change if you want to include into the official version.

just replace line 404 in qrious.js

from: var offset = this.getOffset(frame);

to: var offset=parseInt((this.element.width-(frame.width*moduleSize))/2);

tested across a variety of sizes and content

alieslamifard commented 6 years ago

why not done yet?!! it's an old issue with simple solution!

blizzardengle commented 5 years ago

This is actually implemented already but is blocked from ever running. Take a look at the getOffset() function starting at line 330. If you provide a padding value that value is what is returned here, if you fail to provide a padding value 0 is returned anyways so this centering math is never run. Change the padding if() check to this code and it works properly:

if (padding != null) {
    if(padding > 0){
        return padding;
    }
}

With this change you leave line 404 alone and don't add your code. The getOffset() function already has it.