Skip to content

Instantly share code, notes, and snippets.

@ShinoharaTa
Last active May 22, 2019 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShinoharaTa/afa2fe567f4ba12dc8dc99b66da75bc7 to your computer and use it in GitHub Desktop.
Save ShinoharaTa/afa2fe567f4ba12dc8dc99b66da75bc7 to your computer and use it in GitHub Desktop.
jQuery QR Codeの問題点と解決 ref: https://qiita.com/Shino3/items/8373e4c96a354d6c38cc
$("#tipQR").html("");
$("#tipQR").qrcode({ width: 240, height: 240, text: "Shino3(e)" });
// compute tileW/tileH based on options.width/options.height
- var tileW = options.width / qrcode.getModuleCount();
- var tileH = options.height / qrcode.getModuleCount();
+ var tileW = options.width / (qrcode.getModuleCount() + 8);
+ var tileH = options.height / (qrcode.getModuleCount() + 8);
// draw in the canvas
- for( var row = 0; row < qrcode.getModuleCount(); row++ ){
- for( var col = 0; col < qrcode.getModuleCount(); col++ ){
- ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background;
- var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW));
- var h = (Math.ceil((row+1)*tileH) - Math.floor(row*tileH));
- ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h);
- }
- }
+ for (var row = 0; row < (qrcode.getModuleCount() + 8); row++) {
+ for (var col = 0; col < (qrcode.getModuleCount() + 8); col++) {
+ if ((row < 4) || (row >= (qrcode.getModuleCount() + 4))) {
+ ctx.fillStyle = options.background;
+ }
+ else if ((col < 4) || (col >= (qrcode.getModuleCount() + 4)))
+ {
+ ctx.fillStyle = options.background;
+ }
+ else
+ {
+ ctx.fillStyle = qrcode.isDark(row - 4, col - 4) ? options.foreground : options.background;
+ }
+ var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
+ var h = (Math.ceil((row + 1) * tileH) - Math.floor(row * tileH));
+ ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
+ }
+ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment