qrcodejs icon indicating copy to clipboard operation
qrcodejs copied to clipboard

QRcode logo

Open abeinoo opened this issue 7 years ago • 5 comments

How Can I branded the qrcode , put image or logo on qrcode

abeinoo avatar Sep 26 '17 09:09 abeinoo

You have to do it yourself. It's not too difficult:

  1. Load the generated PNG into a canvas
  2. Draw your image into the exact center with a width and height of at most 1/3 of the QR code size

AyrA avatar Dec 08 '17 16:12 AyrA

Hi! I want to use it in WeChat small program;and i want to Setting the style of the icon,Is there any good way to do it,

babydada avatar Apr 10 '18 01:04 babydada

@AyrA did you have any example to do this .... Thanks

Usamaliaquat123 avatar Jun 22 '20 09:06 Usamaliaquat123

Something similar to this:

function imgQR(qrCanvas, centerImage, factor) {
	var h = qrCanvas.height;

	//Center size
	var cs = h * factor;
	//Center offset
	var co = (h - cs) / 2;

	var ctx = qrCanvas.getContext("2d");
	ctx.drawImage(centerImage, 0, 0, centerImage.width, centerImage.height, co, co, cs, cs);
}

Note: this is untested code. It might need some tweaking. Supply the canvas with the qr code already drawn, the image to draw, and the scaling factor. I would start with something small like 0.25

AyrA avatar Jun 22 '20 12:06 AyrA

this a small example, hope it can help to you

function imgQR(qrCanvas, centerImage, factor) {
    var h = qrCanvas.height;
    //Center size
    var cs = h * factor;
    //Center offset
    var co = (h - cs) / 2;
    var ctx = qrCanvas.getContext("2d");
    ctx.drawImage(centerImage, 0, 0, centerImage.width, centerImage.height, co, co, cs, cs);
  }
  const icon = new Image();
  icon.onload = function () {
    var qrcode = new QRCode(document.getElementById("qrcode"), {
      text: "https://docs.apipost.cn/preview/c1965f884871c5e8/022649a12cdf1ad7",
      width: 200,
      height: 200,
      colorDark: "#000000",
      colorLight: "#ffffff",
      correctLevel: QRCode.CorrectLevel.H
    });
    imgQR(qrcode._oDrawing._elCanvas, this, 0.2)
  }
  icon.src = './success.png';

hickiy avatar Jul 07 '22 05:07 hickiy