Socket
Socket
Sign inDemoInstall

qrcode

Package Overview
Dependencies
66
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    qrcode

QRCode / 2d Barcode api with both server side and client side support using canvas


Version published
Weekly downloads
2.1M
increased by5.66%
Maintainers
1
Install size
98.8 MB
Created
Weekly downloads
 

Package description

What is qrcode?

The qrcode npm package is a library for generating QR codes. It can be used to create QR codes in various formats such as images or canvas for web applications, and it supports a range of customization options.

What are qrcode's main functionalities?

Generating QR Code as Data URL

This feature allows you to generate a QR code as a data URL, which can be used directly in image tags or CSS backgrounds.

const QRCode = require('qrcode');
QRCode.toDataURL('https://www.example.com', function (err, url) {
  console.log(url);
});

Generating QR Code as PNG Image File

This feature allows you to generate a QR code and save it as a PNG image file on the filesystem.

const QRCode = require('qrcode');
QRCode.toFile('path/to/output.png', 'https://www.example.com', function (err) {
  if (err) throw err;
  console.log('QR Code saved as image file!');
});

Generating QR Code as UTF8 String

This feature allows you to generate a QR code as a UTF8 string, which can be printed to the terminal or used in text-based formats.

const QRCode = require('qrcode');
QRCode.toString('https://www.example.com', { type: 'terminal' }, function (err, string) {
  if (err) throw err;
  console.log(string);
});

Other packages similar to qrcode

Readme

Source

Build Status

node-qrcode

This is a server side QR code / 2d barcode generator. it is an extension of "QRCode for JavaScript" which Kazuhiko Arase thankfully mit licensed

the qrcode-draw.js can be used directly as a client side lib if its appended too or included with lib/qrcode.js to use this on the server side please require('qrcode'); =)

examples

simple test


	var QRCode = require('qrcode');

	QRCode.toDataURL('i am a pony!',function(err,url){
		console.log(url);
	});

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.


    <!--[if ie]><script type="text/javascript" src="/vendors/excanvas/excanvas.js"></script><![endif]-->
		<script src="/build/qrcode.js"></script>
		<canvas id="test"></canvas>
		<script>

		  var qrcodedraw = new qrcodelib.qrcodedraw();
		  //triggered errors will throw
		  qrcodedraw.errorbehavior.length = false;

			qrcodedraw.draw(document.getElementByID('test'),text,function(error,canvas){
			  if(error) {
			    if(window.console && window.console.warn) {
			      console.warn(error);
			    } else {
			      alert(error);
			    }
			  }
			});
    </script>

remeber to put excanvas and qrcode.js somewhere where your browser can find them

server side api

QRCode.draw(text, [optional options], cb(error,canvas)); returns 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

QRCode.toDataURL(text, [optional options], cb(error,dataURL)); returns mime image/png data url for the 2d barcode

QRCode.save(path, text, [optional options] , cb(error,written)); saves png to the path specified returns bytes written

QRCode.drawText(text, [optional options],cb) returns an ascii representation of the qrcode using unicode characters and ansi control codes for background control.

QRCode.drawBitArray(text, [optional options], cb(error,bits,width)); 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 =)

client side api

window.qrcodelib

  • .qrcodedraw() Constructor

qrcodedraw instance

  • .draw(canvasElement,text,[optional options],cb);

for quick client side use:

  • run node test/clientsideserver.js
  • open localhost:3031 in your browser

the javascript is in test/clientside.html

qr code capacity.

this libary can encode a string up to lengths: 2953 in error correct level L 2331 in error correct level M 1663 in error correct level Q 1273 in error correct level H

the default is H. 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.

install

npm install qrcode

to use qrcode from the command line to save  qrcode images or generate ones you can view in your termial

npm install -g qrcode 

node-canvas is a native module and requires dev packages of cairo and pixman to compile. on ubuntu you can install them with apt-get and npm install will work great.


sudo apt-get install libpixman-1-dev libcairo2-dev

it is my higest priority for this module to use an all js png encoder and remove this dep.

dependencies

these should be taken care of for you by npm but you should

npm install canvas

if cairo gives you trouble and you cannot install canvas checkout the canvas site i know tj 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

Keywords

FAQs

Last updated on 14 Oct 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc