Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no option to put padding #275

Open
venkatesh-alivenow opened this issue Jun 2, 2022 · 3 comments
Open

There is no option to put padding #275

venkatesh-alivenow opened this issue Jun 2, 2022 · 3 comments

Comments

@venkatesh-alivenow
Copy link

We are not able to put padding around. It is not working properly without padding.

@thuijzer
Copy link

<div id="qrcode" style="padding:2rem"></div>

@DamianoP
Copy link

DamianoP commented Apr 9, 2024

<div id="qrcode" style="padding:2rem"></div>

It would be useful if the generated image had custom padding, so you could right-click to save the image with the QR code, doing "save as image."
The proposed solution adds padding to the div containing the QrCode but if you want to save as an image the padding is not saved with it.

@github-renault-LT
Copy link

You may try this (I have not made any error checking)

In QRCode = function (el, vOption) {
Add paddingX and paddingY values to this._htOption

    this._htOption = {
      width : 256,
      height : 256,
      typeNumber : 4,
      colorDark : "#000000",
      colorLight : "#ffffff",
      correctLevel : QRErrorCorrectLevel.H,
      paddingX: 8,
      paddingY: 8
    };

In var Drawing = function (el, htOption) {

Replace

      this._elCanvas.width = htOption.width;
      this._elCanvas.height = htOption.height;

by

      this._elCanvas.width = htOption.width + (htOption.paddingX || 8);
      this._elCanvas.height = htOption.height + (htOption.paddingY || 8);

In Drawing.prototype.draw = function (oQRCode) {

Add

      var nPaddingX = (_htOption.paddingX / 2 || 4);
      var nPaddingY = (_htOption.paddingY / 2 || 4);

In the for (var col = 0; col < nCount; col++) {

Replace

          var nLeft = col * nWidth;
          var nTop = row * nHeight;

by

          var nLeft = col * nWidth + nPaddingX;
          var nTop = row * nHeight + nPaddingY;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants