qr-image vs qrcode
二维码生成
qr-imageqrcode类似的npm包:

二维码生成

二维码生成库是用于在Node.js应用程序中创建二维码图像的工具。这些库允许开发者根据输入的数据(如文本、URL或其他信息)生成二维码,并将其输出为图像文件或直接在网页上显示。二维码(Quick Response Code)是一种二维条形码,可以存储大量信息,广泛应用于支付、营销、身份验证等场景。qr-image是一个简单易用的库,支持生成二维码图像并保存为多种格式;而qrcode则提供更丰富的功能,包括自定义样式、错误修正级别和支持生成SVG格式。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
qr-image01,064-149 年前MIT
qrcode08,105135 kB1232 年前MIT

功能对比: qr-image vs qrcode

功能丰富性

  • qr-image:

    qr-image提供基本的二维码生成能力,支持将二维码输出为PNG、JPEG和SVG格式。它的功能相对简单,适合快速生成二维码。

  • qrcode:

    qrcode提供更丰富的功能,包括自定义颜色、错误修正级别、支持生成SVG和HTML格式。它允许更高程度的自定义,适合需要设计美观二维码的应用。

自定义能力

  • qr-image:

    qr-image的自定义能力有限,主要集中在二维码的大小和输出格式上。它不支持颜色或样式的深入自定义。

  • qrcode:

    qrcode提供更强的自定义能力,允许开发者设置二维码的前景色、背景色、错误修正级别等。它支持更复杂的样式设置,适合需要品牌化二维码的项目。

错误修正

  • qr-image:

    qr-image支持基本的错误修正,但没有提供详细的配置选项。错误修正级别是固定的,适合一般用途。

  • qrcode:

    qrcode支持多级错误修正,开发者可以根据需要选择不同的错误修正级别(L、M、Q、H),提供更大的灵活性和可靠性。

输出格式

  • qr-image:

    qr-image支持生成PNG、JPEG和SVG格式的二维码图像,适合大多数应用场景。

  • qrcode:

    qrcode支持生成PNG、SVG、HTML等多种格式,特别是在SVG和HTML方面提供了更好的支持,适合需要矢量图或嵌入式二维码的应用。

示例代码

  • qr-image:

    使用qr-image生成二维码

    const qr = require('qr-image');
    const fs = require('fs');
    
    // 生成二维码并保存为PNG文件
    const qrSvg = qr.imageSync('Hello, QR Code!', { type: 'png' });
    fs.writeFileSync('qrcode.png', qrSvg);
    
    // 生成二维码并保存为SVG文件
    const qrSvg = qr.imageSync('Hello, QR Code!', { type: 'svg' });
    fs.writeFileSync('qrcode.svg', qrSvg);
    
  • qrcode:

    使用qrcode生成二维码

    const QRCode = require('qrcode');
    
    // 生成二维码并保存为PNG文件
    QRCode.toFile('qrcode.png', 'Hello, QR Code!', {
      errorCorrectionLevel: 'H', // 设置错误修正级别
      color: {
        dark: '#000', // 前景色
        light: '#FFF' // 背景色
      }
    });
    
    // 生成SVG格式的二维码
    QRCode.toString('Hello, QR Code!', { type: 'svg' }, (err, svg) => {
      console.log(svg);
    });
    

如何选择: qr-image vs qrcode

  • qr-image:

    选择qr-image如果您需要一个简单、快速的解决方案来生成二维码图像,特别是当您只需要基本功能而不需要复杂的自定义时。它适合快速原型开发和小型项目。

  • qrcode:

    选择qrcode如果您需要更高级的功能,如自定义颜色、错误修正级别和支持生成SVG格式。它适合需要更多灵活性和自定义选项的中大型项目。

qr-image的README

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 (???).