This package allows you to generate barcodes and QR codes with custom styling, including support for multiple colors for barcodes. By default, the QR code is black and white, but you can easily customize the colors of the barcode lines.
To install this package, use npm:
npm install qr-barcode-generator
To generate a QR code, simply call the generateQRCode
method, passing in the data you want to encode.
const BarcodeQRGenerator = require('qr-barcode-generator');
// Generate QR Code
BarcodeQRGenerator.generateQRCode('Hello World!')
.then((qrCode) => {
console.log("QR Code Base64 String: ", qrCode);
})
.catch(console.error);
By default, the QR code is black on a white background.
To generate a barcode, call the generateBarcode
method, passing in the data and optional configuration.
const BarcodeQRGenerator = require('qr-barcode-generator');
// Generate Barcode with custom color
const barcode = BarcodeQRGenerator.generateBarcode('123456789', { color: 'blue' });
console.log("Barcode Base64 String:", barcode);
The generateBarcode
function accepts the following optional settings:
-
color
: Customize the line color of the barcode (default:black
).- Valid colors:
black
,white
,red
,green
,blue
,yellow
,cyan
,magenta
,orange
,purple
,pink
,brown
,grey
,lime
,indigo
.
- Valid colors:
You can choose from the following colors for the barcode lines:
-
black
:#000000
-
white
:#FFFFFF
-
red
:#FF0000
-
green
:#008000
-
blue
:#0000FF
-
yellow
:#FFFF00
-
cyan
:#00FFFF
-
magenta
:#FF00FF
-
orange
:#FFA500
-
purple
:#800080
-
pink
:#FFC0CB
-
brown
:#A52A2A
-
grey
:#808080
-
lime
:#00FF00
-
indigo
:#4B0082
To generate a barcode with custom color (using one of the predefined color names):
const barcode = BarcodeQRGenerator.generateBarcode('123456789', { color: 'blue' });
console.log("Barcode with Blue Color:", barcode);
const BarcodeQRGenerator = require('qr-barcode-generator');
// Generate QR Code
BarcodeQRGenerator.generateQRCode('Hello World!').then((qrCode) => {
console.log("QR Code with Custom Colors:", qrCode);
}).catch(console.error);
// Generate Barcode with custom color
const barcode = BarcodeQRGenerator.generateBarcode('123456789', { color: 'blue' });
console.log("Barcode with Blue Color:", barcode);
MIT License. See LICENSE file for more information.
- The barcode generation allows for complete color customization from a list of predefined colors. If no color is provided, the default will be black.