QR code generation library in javascript

2019-01-10 03:28发布

I'm currently looking for a js library that can encode text in qr codes. The only one I've been able to find so far seems broken, although other people claim to be using it. The sample page doesn't work. By playing a bit with it I managed to generate codes but they don't get decoded by the phone software.

Is there another library is js for this? Has anyone managed to get it to work?

I'm not interested in a solution that pulls the code from an online service (kaywa, google etc.).


Update:

Well, you guys are right, that library does work. My problem was that I tried including it in a HTML5 Boilerplate page, and document.write doesn't seem to work in that. I modified the sample code anyway to make the browser draw in a canvas not a table and I got the order of the fillRect function backwards. Below is the corrected function call.

context.fillRect(c * UNIT_SIZE, r * UNIT_SIZE, UNIT_SIZE, UNIT_SIZE);
// it's column-row, not row-column; don't ask why :)

Since I don't get my image transposed anymore :), now the qr decodes fine. Thanks for the support.

10条回答
Explosion°爆炸
2楼-- · 2019-01-10 04:17

If you can't find a native JavaScript implementation, you can always AJAX the image yourself from your server.

http://www.swetake.com/qr/qr_cgi_e.html

查看更多
forever°为你锁心
3楼-- · 2019-01-10 04:19

As Canvas/PNG

There is also the new kjua from the same author as the "old" jQuery.qrcode.

As Canvas/PNG/SVG

And QR-Code-generator by @nayuki also has the ability to create QR codes as SVGs.

查看更多
Rolldiameter
4楼-- · 2019-01-10 04:21

There is a simple JavaScript library which I found sometime back called QRCode.js.

QRCode.js is a cross-browser JavaScript library which allows you to generate QRCodes on the fly, on the client-side. QRCode.js makes use of HTMl5 Canvas and Tables to display the QRCode. The library itself has no dependencies whatsoever.

To generate a QRCode, you just need to include the JavaScript library and then pass as parameters to the QRCode function, the text you want to encode as the QRCode, the width & height of the QRCode you want to display, as well as your specified foreground color and background color.

查看更多
Luminary・发光体
5楼-- · 2019-01-10 04:22

The QR code in the initial post only supports up to 271 bytes (version 10, Size = 57x57, EC level L).

To make it support the full specs of QR code (version 40, 177x177, 2953 bytes), you have to add more values into its RS_BLOCK_TABLE.

See the remaining matrices (version 11-40) here: http://two.pairlist.net/pipermail/reportlab-users/2010-September/009707.html

查看更多
登录 后发表回答