qr-image vs qrcode
Generating QR Codes in Node.js and Browser Environments
qr-imageqrcodeSimilar Packages:

Generating QR Codes in Node.js and Browser Environments

qr-image and qrcode are both popular libraries for generating QR codes in JavaScript, but they serve different architectural needs. qr-image is a lightweight, stream-based library primarily designed for Node.js server-side generation, outputting image buffers directly. qrcode is a more versatile, isomorphic library that supports both Node.js and browser environments, offering multiple output formats including SVG, Canvas, and terminal text. While qr-image focuses on simplicity and speed for backend image creation, qrcode provides a richer API for client-side rendering and customization.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
qr-image01,065-1510 years agoMIT
qrcode08,128135 kB1232 years agoMIT

QR Code Generation: qr-image vs qrcode

When adding QR code functionality to a JavaScript project, the choice between qr-image and qrcode often comes down to environment constraints and output requirements. Both libraries solve the same core problem β€” encoding data into a scannable matrix β€” but they approach the implementation differently. Let's look at how they handle real-world engineering scenarios.

πŸ–₯️ Environment Support: Node.js Only vs Isomorphic

qr-image is built strictly for Node.js.

  • It relies on Node.js streams and buffer handling.
  • You cannot use it directly in a browser bundle without polyfills or server-side rendering.
// qr-image: Node.js only
const qr = require('qr-image');

const qrSvg = qr.imageSync('https://example.com', { type: 'svg' });
// Returns a Buffer containing SVG data

qrcode works in both Node.js and browsers.

  • It detects the environment and adapts its rendering engine.
  • You can use the same package for server-side generation and client-side Canvas drawing.
// qrcode: Isomorphic
const QRCode = require('qrcode');

// Works in Node.js
QRCode.toFile('./qr.png', 'https://example.com');

// Works in Browser
QRCode.toCanvas(canvasElement, 'https://example.com');

πŸ–ΌοΈ Output Formats: Image Buffers vs Multiple Renderers

qr-image focuses on image file formats.

  • Supports PNG, SVG, EPS, and PDF.
  • Returns raw buffers or streams, making it easy to pipe into HTTP responses.
// qr-image: Stream output
const qr = require('qr-image');
const fs = require('fs');

const qrStream = qr.image('https://example.com', { type: 'png' });
qrStream.pipe(fs.createWriteStream('qr.png'));

qrcode supports a wider range of output types.

  • Includes PNG, SVG, Canvas, Terminal text, and UTF8 strings.
  • Better for debugging or displaying QR codes directly in a command-line interface.
// qrcode: Terminal output
const QRCode = require('qrcode');

QRCode.toString('https://example.com', { type: 'terminal' }, (err, string) => {
  console.log(string); // Prints QR code to console
});

βš™οΈ Configuration: Minimal vs Detailed Control

qr-image offers basic configuration options.

  • You can set size, margin, and error correction level.
  • Customization is limited compared to modern frontend needs.
// qr-image: Basic options
const qr = require('qr-image');

const qrPng = qr.imageSync('data', {
  ec_level: 'M',
  size: 10,
  margin: 1
});

qrcode provides granular control over appearance.

  • Allows color customization (dark/light modules), scaling, and width.
  • Essential for branding QR codes to match application themes.
// qrcode: Advanced styling
const QRCode = require('qrcode');

QRCode.toCanvas('https://example.com', {
  width: 300,
  margin: 2,
  color: {
    dark: '#000000',
    light: '#ffffff'
  }
}, (err, canvas) => {
  // Render canvas to DOM
});

πŸ”„ API Style: Synchronous Buffers vs Promises

qr-image uses a mix of sync and stream-based APIs.

  • imageSync returns a buffer immediately.
  • image returns a stream for async piping.
// qr-image: Synchronous buffer
const buffer = qr.imageSync('text');
// Use buffer directly

qrcode embraces Promises and async/await.

  • Most methods return Promises, fitting modern JavaScript workflows.
  • Callbacks are supported but Promises are preferred for clarity.
// qrcode: Promise-based
const url = await QRCode.toDataURL('https://example.com');
// Use data URL in img src

πŸ“¦ Dependency Footprint: Lightweight vs Feature-Rich

qr-image has very few dependencies.

  • It focuses solely on generating the image matrix and encoding it.
  • Good for serverless functions where cold start time matters.
// qr-image: Minimal setup
// No complex configuration needed for basic usage
const qr = require('qr-image');

qrcode includes more built-in features.

  • Handles Canvas manipulation and terminal rendering internally.
  • Slightly larger footprint but reduces the need for additional image libraries.
// qrcode: All-in-one
// No need for separate canvas or svg libraries for basic rendering
const QRCode = require('qrcode');

🌐 Real-World Scenarios

Scenario 1: Backend Invoice Generation

You need to embed a QR code on a PDF invoice generated on the server.

  • βœ… Best choice: qr-image
  • Why? You just need a PNG buffer to embed in the PDF. No browser logic required.
// qr-image: Embed in PDF
const qrBuffer = qr.imageSync(invoiceUrl, { type: 'png' });
pdfDoc.image(qrBuffer, { x: 50, y: 50 });

Scenario 2: Interactive Web App

Users generate QR codes dynamically in the browser to share profiles.

  • βœ… Best choice: qrcode
  • Why? You need Canvas or SVG rendering directly in the DOM without server round-trips.
// qrcode: Browser rendering
QRCode.toCanvas(document.getElementById('canvas'), userProfileUrl);

Scenario 3: CLI Tool

You are building a command-line tool to share Wi-Fi credentials.

  • βœ… Best choice: qrcode
  • Why? Terminal output allows users to scan directly from their screen.
// qrcode: CLI output
console.log(await QRCode.toString(wifiString, { type: 'terminal' }));

πŸ“Œ Summary Table

Featureqr-imageqrcode
EnvironmentπŸ–₯️ Node.js only🌐 Node.js + Browser
Output TypesπŸ–ΌοΈ PNG, SVG, EPS, PDF🎨 PNG, SVG, Canvas, Terminal
API Style⚑ Sync Buffers / StreamsπŸ”— Promises / Callbacks
CustomizationπŸ”§ Basic (size, margin)🎨 Advanced (colors, scaling)
DependenciesπŸƒ MinimalπŸ“¦ Moderate
Use CaseπŸ“„ Server-side file generationπŸ–±οΈ Client-side rendering

πŸ’‘ The Big Picture

qr-image is like a specialized factory machine 🏭 β€” it does one job (image generation) very efficiently in a Node.js environment. It is perfect for backend services, batch processing, or any scenario where you need raw image data without frontend overhead.

qrcode is like a Swiss Army knife πŸ”ͺ β€” it adapts to where you use it, whether that's a server, a browser, or a terminal. It is the right choice for modern web applications that need flexibility, customization, and isomorphic code sharing.

Final Thought: If your QR codes live on the server, qr-image keeps things simple. If they live in the user's hands (browser or CLI), qrcode gives you the tools to make them work seamlessly.

How to Choose: qr-image vs qrcode

  • qr-image:

    Choose qr-image if you are building a Node.js backend service that needs to generate QR code image files (PNG, SVG, EPS) quickly without browser dependencies. It is ideal for scenarios where you need to stream images directly to a response or save them to disk with minimal configuration. Avoid this package for client-side or isomorphic applications since it relies on Node.js streams.

  • qrcode:

    Choose qrcode if you need to generate QR codes in the browser, require multiple output formats like Canvas or terminal text, or need an isomorphic solution that works in both Node.js and client environments. It is better suited for applications that demand customization of margins, error correction levels, and color schemes directly in the frontend.

README for qr-image

qr-image

npm version

This is yet another QR Code generator.

Overview

  • No dependecies;
  • generate image in png, svg, eps and pdf formats;
  • numeric and alphanumeric modes;
  • support UTF-8.

Releases

Installing

npm install qr-image

Usage

Example:

var qr = require('qr-image');

var qr_svg = qr.image('I love QR!', { type: 'svg' });
qr_svg.pipe(require('fs').createWriteStream('i_love_qr.svg'));

var svg_string = qr.imageSync('I love QR!', { type: 'svg' });

More examples

qr = require('qr-image')

Methods

  • qr.image(text, [ec_level | options]) β€” Readable stream with image data;
  • qr.imageSync(text, [ec_level | options]) β€” string with image data. (Buffer for png);
  • qr.svgObject(text, [ec_level | options]) β€” object with SVG path and size;
  • qr.matrix(text, [ec_level]) β€” 2D array.

Options

  • text β€” text to encode;
  • ec_level β€” error correction level. One of L, M, Q, H. Default M.
  • options β€” image options object:
    • ec_level β€” default M.
    • type β€” image type. Possible values png (default), svg, pdf and eps.
    • size (png and svg only) β€” size of one module in pixels. Default 5 for png and undefined for svg.
    • margin β€” white space around QR image in modules. Default 4 for png and 1 for others.
    • customize (only png) β€” function to customize qr bitmap before encoding to PNG.
    • parse_url (experimental, default false) β€” try to optimize QR-code for URLs.

Changes

  • Use zlib.deflateSync instead of pako.
  • Fix deprecation warning for NodeJS 7.

TODO

  • Tests;
  • mixing modes;
  • Kanji (???).