neocotic / qrious

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

padding not null toDataUrl Picture not centered #123

Open milabi opened 3 years ago

milabi commented 3 years ago

下载 (2)

qr.background = '#cfcfcf'; qr.backgroundAlpha = 1.0; qr.foregroundAlpha = 1.0; qr.foreground = '#000000'; qr.level = 'L'; qr.padding = 10; qr.size = 220; qr.value = 'https://github.com/neocotic/qrious/issues/123';

cibersheep commented 3 years ago

I had this on the old code. Try removing Math.floor here: https://github.com/neocotic/qrious/blob/master/dist/qrious.js#L312

roblewisink commented 1 year ago

I realize this is an old thread, but wanted to add a note for anyone else who may be looking for a solution to the padding issue.

It appears to me that the getModuleSize function already accounts for the padding value. As such, there is no need to add a condition in the getOffset function to handle padding.

I made the following edit with positive results:

getOffset: function(frame) {
      var qrious = this.qrious;
      /* var padding = qrious.padding;
      *
      *  if (padding != null) {
      *   return padding;
      * }
      */
      var moduleSize = this.getModuleSize(frame);
      var offset = Math.floor((qrious.size - (moduleSize * frame.width)) / 2);
      return Math.max(0, offset);
    },
ROBERT-MCDOWELL commented 1 year ago

thanks! try to make a PR so maybe the author will merge it!