ChrisCinelli / branded-qr-code

npm module to create QR Codes with a logo
67 stars 20 forks source link

Create branded QRcodes

NPM module to create QR Codes with a logo like these...

callme

apple here mrjs supermanemail

playstation smshere nyancat

our-wifi iphonesonebay

Install

yarn add branded-qr-code babel-polyfill

Use

// ESNext Modules
import 'babel-polyfill';
import brandedQRCode from 'branded-qr-code';
// Or old good syntax
// require('babel-polyfill');
// var brandedQRCode = require('branded-qr-code');

// Return a buffer with the PNG of the code
brandedQRCode.generate({text: 'https://www.google.com', path: 'mylogo.png'});

// For express if you need different logos:
app.get('/qr/:logo', route({ getLogoPath: req => `../images/original/${req.params.logo}.png` }));

Examples

Standard express server - Check the demo with npm run demo. Try localhost:3000/qr/twitter?t=www.twitter.com.

Batch Processing - Check the demo with npm run demo-generate. Files are saved in demos/generate/output.

Syntax

// Return a Buffer with the QRCode's PNG
brandedQRCode.generate( opts )
// Return an express route that serves the QRCode's PNG
brandedQRCode.route( opts )

Utilities

There are some /scripts that can help you to create a better looking logos adding some white margin around it. Just place your logo in /images/original and then, run in order:

  1. npm run resize
  2. npm run gaussian
  3. npm run finalize

You will find your logo nicely padded in /images/final

More about QRcodes

The logo at the center of the QRcode is actually adding noise. The QR code can still be decoded because QR codes have redundant data that readers' error correction algorithms can use. The npm qrcode library supports different levels. Higher levels produce denser the QR codes. From empirical tests you can noticed that using Low (L) usually produces QR codes that are NOT READABLE. Medium (M) is the default and it is usually sufficient. If you have problems, you may want to use quartile (Q) or high (H). You can do it with { errorCorrectionLevel: 'Q' }.

Development notes: