QRCode / 2d Barcode api with both server side and client side support using canvas
This is a server side QR code/2d barcode generator.
qrcode-draw.js can be used directly as a client side lib if its appended too or included with
To use this on the server side please
A simple server side test...
var QRCode = require'qrcode';QRCodetoDataURL'i am a pony!'console.logurl;;
In your terminal if you install globally...
qrcode "hi i want a qrcode"qrcode "i like to save qrs to file" qr.png
In client side HTML...
Remember to put
qrcode.js somewhere where your browser can find them.
QRCodedrawtext optional options cberrorcanvas;
Returns a node canvas object see https://github.com/LearnBoost/node-canvas for all of the cool node things you can do. Look up the canvas api for the other cool things.
QRCodetoDataURLtext optional options cberrordataURL;
Returns mime image/png data url for the 2d barcode.
QRCodesavepath text optional options cberrorwritten;
Saves png to the path specified returns bytes written.
QRCodedrawTexttext optional optionscb
Returns an ascii representation of the qrcode using unicode characters and ansi control codes for background control.
QRCodedrawBitArraytext optional options cberrorbitswidth;
Returns an array with each value being either 0 light or 1 dark and the width of each row. This is enough info to render a qrcode any way you want. =)
Can be one of the values in
Can be a string. one of
undefined, defaults to H which is max error correction.
If invalid value, defaults to minimum error correction.
qrcode =qrcodedrawcanvasElementtextoptional optionscb;
For quick client side use...
node test/clientsideserver.jsopen http://localhost:3031
This libary can encode this many bytes at each error correct level:
The default is H.
please note as pointed out by @giacecco that byte length is often greater than string length due to multibyte characters.
// so use the byte lengthstrlength// instead of the string lengthstrlength
It can now be changed in an ugly way that wont be supported for more then another few days if you really need to. Also the default module size at qr version 40 is really too small for the camera on my Nexus 1 and to make it larger i run out of screen to show it. At 40 the barcode scanner even finds random UPC 1d barcodes in the mass of little squares. the default module size cannot be changed through the public api at this time.
npm install qrcode
To use qrcode from the command line to save qrcode images or generate ones you can view in your terminal...
npm install -g qrcode
node-canvas is a native module and requires dev packages of
pixman to compile.
On ubuntu you can install them with
npm install will work great.
sudo apt-get install libpixman-1-dev libcairo2-dev libpangocairo-1.0-0 libpango1.0-dev libgif-dev
It is my higest priority for this module to use an all
js png encoder and remove this dep.
These should be taken care of for you by npm but you should...
npm install canvas
cairo gives you trouble and you cannot install
canvas, checkout the canvas site. I know @tjholowaychuk has setup a way to download and install a version of cairo/pixman for testing.
The word "QR Code" is registered trademark of:
DENSO WAVE INCORPORATED