qrcode-generator-sabai
Overview
qrcode-generator-sabai is a Node.js package designed to simplify QR code generation from various payloads to images. It offers ease of use and extensive customization options.
Features
- Generate QR Codes: Convert text, URLs, or any payload into QR codes effortlessly.
- Customization: Tailor QR code attributes such as size, error correction level, and central logo placement to suit your needs.
- Export Options: Export QR codes as PNG images, SVG strings, or Base64 encoded formats for versatile usage.
Installation
To install qrcode-generator-sabai, execute the following command in your terminal:
npm install qrcode-generator-sabai
Getting Started
Import the package into your Node.js project:
const QRCode = require('qrcode-generator-sabai');
Here's a basic example of generating a QR code:
PNG Format:
const QRCode = require('qr-code-sabai');
async function generateQRCode() {
try {
const qrCode = await QRCode.generateQR(
'https://github.com/iamlex01/qrcode-generator-sabai#readme',
400,
"H"
).toPng(
'qr-code.png',
'./public/images'
);
console.log('QR Code generated successfully:', qrCode);
} catch (error) {
console.error('Error generating QR Code:', error);
}
}
generateQRCode();
SVG Format:
const QRCode = require('qrcode-generator-sabai');
async function generateQRCode() {
try {
const qrCode = await QRCode.generateQR(
'https://github.com/iamlex01/qrcode-generator-sabai#readme',
400,
"H"
).toSvg();
console.log('QR Code generated successfully:', qrCode);
} catch (error) {
console.error('Error generating QR Code:', error);
}
}
generateQRCode();
Base64 Format:
const QRCode = require('qrcode-generator-sabai');
async function generateQRCode() {
try {
const qrCode = await QRCode.generateQR(
'https://github.com/iamlex01/qrcode-generator-sabai#readme',
400,
"H"
).toBase64();
console.log('QR Code generated successfully:', qrCode);
} catch (error) {
console.error('Error generating QR Code:', error);
}
}
generateQRCode();
Here's a basic example of generating a QR code with central logo placement:
QR Code with Central Logo (PNG Format):
const QRCode = require('qrcode-generator-sabai');
async function generateQRCode() {
try {
const qrCode = await QRCode.generateQR(
'https://github.com/iamlex01/qrcode-generator-sabai#readme',
400,
"H"
).toImageWithLogo(
'qr-code-with-logo.png',
'./public/images',
'./path/to/logo.png',
);
console.log('QR Code with logo generated successfully:', qrCode);
} catch (error) {
console.error('Error generating QR Code:', error);
}
}
generateQRCode();
QR Code with Central Logo (Base64 Format):
const QRCode = require('qrcode-generator-sabai');
async function generateQRCode() {
try {
const qrCode = await QRCode.generateQR(
'https://github.com/iamlex01/qrcode-generator-sabai#readme',
400,
"H"
).toImageWithLogo(
'./path/to/logo.png',
);
console.log('QR Code with logo generated successfully:', qrCode);
} catch (error) {
console.error('Error generating QR Code:', error);
}
}
generateQRCode();
Error Correction Level
Error correction capability allows QR codes to be scanned successfully even if the symbol is dirty or damaged. Four levels are available to choose from according to the operating environment.
Higher levels offer better error resistance but reduce the symbol's capacity. If the chances that the QR code symbol may be corrupted are low (for example, if it is displayed on a monitor), it is possible to safely use a low error level such as Low or Medium.
Possible levels are as follows:
Level | Error Resistance |
---|
L (Low) | ~7% |
M (Medium) | ~15% |
Q (Quartile) | ~25% |
H (High) | ~30% |
The percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.
License
qrcode-generator-sabai is licensed under the MIT License. Feel free to use and modify it according to your needs.