­

qrcode將生成的二維碼轉成圖片格式

  • 2019 年 11 月 6 日
  • 筆記

微信里打開頁面時需要長按識別二維碼,所以需要轉下圖片

<div id="qrcode"></div>  <img id="img"/>
//默認使用Canvas生成,並顯示到圖片   var qrcode = $('#qrcode').qrcode('http://www.tiaocaoer.com/').hide();   var canvas = qrcode.find('canvas').get(0);   $('#img').attr('src',canvas.toDataURL('image/jpg'));

qrcodejs參數說明

參數名稱

默認值

類型

說明

text

string

需要生成的二維碼內容

width

256

number

影像寬度

height

256

number

影像高度

colorDark

"#000000"

string

前景色

colorLight

"#ffffff"

string

背景色

correctLevel

QRCode.CorrectLevel.L

容錯級別

容錯級別

CorrectLevel等級

最大模糊面積

L(低級)

≤7%

M(中級)

≤15%

Q(四分之一)

≤25%

H(高級)

≤30%

https://github.com/davidshimjs/qrcodejs