jsqr vs qr-image vs qr.js vs qrious vs react-qr-code
QRコード生成と読み取り
jsqrqr-imageqr.jsqriousreact-qr-code類似パッケージ:

QRコード生成と読み取り

QRコード関連のライブラリは、QRコードの生成や読み取りを簡単に行うためのツールです。これらのライブラリは、ウェブアプリケーションやモバイルアプリケーションでQRコードを扱う際に役立ちます。jsqrはQRコードの読み取りに特化したライブラリで、画像からQRコードを解析します。qr-imageはサーバーサイドでQRコードを生成するためのライブラリで、PNGやSVG形式で出力できます。qr.jsはクライアントサイドでQRコードを生成する軽量ライブラリで、シンプルなAPIを提供します。qriousはHTML5のCanvasを使用してQRコードを生成するライブラリで、カスタマイズ性が高いです。react-qr-codeはReactコンポーネントとしてQRコードを生成するライブラリで、Reactアプリケーションに簡単に統合できます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
jsqr04,009-965年前Apache-2.0
qr-image01,063-149年前MIT
qr.js0---13年前MIT
qrious01,625-439年前GPL-3.0
react-qr-code087514.4 kB1515日前MIT

機能比較: jsqr vs qr-image vs qr.js vs qrious vs react-qr-code

QRコード生成

  • jsqr:

    jsqrはQRコードの生成機能を提供していません。主にQRコードの読み取りに特化しています。

  • qr-image:

    qr-imageはサーバーサイドでQRコードを生成する機能を提供します。PNG、SVG、EPS形式で出力でき、カスタマイズ可能な生成が可能です。

  • qr.js:

    qr.jsはクライアントサイドでQRコードを生成するシンプルな機能を提供します。軽量で使いやすく、基本的なQRコード生成に適しています。

  • qrious:

    qriousはHTML5のCanvasを使用してQRコードを生成します。サイズや色、マージンなどをカスタマイズできるため、デザイン性の高いQRコードを作成できます。

  • react-qr-code:

    react-qr-codeはReactコンポーネントとしてQRコードを生成します。動的にデータを変更でき、スタイルやサイズを簡単に調整できます。

QRコード読み取り

  • jsqr:

    jsqrは画像やカメラからQRコードを読み取る機能を提供します。高速で正確な読み取りが可能で、特にモバイルアプリケーションでの使用に適しています。

  • qr-image:

    qr-imageはQRコードの読み取り機能を提供していません。生成に特化したライブラリです。

  • qr.js:

    qr.jsはQRコードの読み取り機能を提供していません。生成に特化したクライアントサイドライブラリです。

  • qrious:

    qriousはQRコードの読み取り機能を提供していません。生成に特化したライブラリです。

  • react-qr-code:

    react-qr-codeはQRコードの読み取り機能を提供していません。生成に特化したReactコンポーネントです。

カスタマイズ性

  • jsqr:

    jsqrは読み取り機能に特化しているため、カスタマイズ性は限られています。読み取り精度やパフォーマンスを調整するための設定はありますが、生成に関するカスタマイズはありません。

  • qr-image:

    qr-imageは生成するQRコードのサイズ、色、マージンなどをカスタマイズできます。特にSVGやEPS形式での出力が可能なため、デザインの自由度が高いです。

  • qr.js:

    qr.jsは基本的なカスタマイズ機能を提供しますが、非常にシンプルなライブラリであるため、複雑なカスタマイズは難しいです。色やサイズの変更は可能ですが、詳細な設定は限られています。

  • qrious:

    qriousはCanvasを使用してQRコードを生成するため、サイズ、色、マージン、背景色などを自由にカスタマイズできます。特にデザイン性を重視したカスタマイズが可能で、複数の設定を簡単に変更できます。

  • react-qr-code:

    react-qr-codeはReactのスタイルプロパティを使用してQRコードの色やサイズをカスタマイズできます。シンプルなカスタマイズが可能で、Reactのコンポーネントとして柔軟に使用できます。

依存関係

  • jsqr:

    jsqrは依存関係がほとんどなく、単一のJavaScriptファイルとして提供されます。これにより、プロジェクトに簡単に統合でき、追加のライブラリをインストールする必要がありません。

  • qr-image:

    qr-imageはNode.js環境で動作するため、サーバーサイドのプロジェクトに統合する必要があります。依存関係は比較的少なく、簡単に使用できます。

  • qr.js:

    qr.jsは依存関係がなく、クライアントサイドで直接使用できる軽量ライブラリです。これにより、追加の設定やインストールなしで簡単に統合できます。

  • qrious:

    qriousはCanvas APIを使用するため、特別な依存関係はありません。ブラウザ環境で直接使用でき、軽量で使いやすいライブラリです。

  • react-qr-code:

    react-qr-codeはReactに依存しているため、Reactプロジェクト内で使用する必要があります。React環境が整っていれば、簡単に統合できます。

Ease of Use: Code Examples

  • jsqr:

    QRコードの読み取り(jsqr

    import jsQR from 'jsqr';
    
    const canvas = document.createElement('canvas');
    const context = canvas.getContext('2d');
    const image = new Image();
    image.src = 'qr-code.png';
    image.onload = () => {
      canvas.width = image.width;
      canvas.height = image.height;
      context.drawImage(image, 0, 0);
      const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
      const code = jsQR(imageData.data, canvas.width, canvas.height);
      if (code) {
        console.log('QR Code Data:', code.data);
      } else {
        console.log('QRコードが見つかりませんでした。');
      }
    };
    
  • qr-image:

    QRコードの生成(qr-image

    const qr = require('qr-image');
    const fs = require('fs');
    
    const data = 'https://example.com';
    const qrImage = qr.image(data, { type: 'png' });
    const writeStream = fs.createWriteStream('qr-code.png');
    qrImage.pipe(writeStream);
    writeStream.on('finish', () => {
      console.log('QRコードが生成されました。');
    });
    
  • qr.js:

    QRコードの生成(qr.js

    <div id="qrcode"></div>
    <script src="path/to/qr.js"></script>
    <script>
      const qrCode = new QRCode(document.getElementById('qrcode'), {
        text: 'https://example.com',
        width: 128,
        height: 128,
      });
    </script>
    
  • qrious:

    QRコードの生成(qrious

    <canvas id="qr-canvas"></canvas>
    <script src="path/to/qrious.min.js"></script>
    <script>
      const qr = new QRious({
        element: document.getElementById('qr-canvas'),
        value: 'https://example.com',
        size: 128,
        background: 'white',
        foreground: 'black',
      });
    </script>
    
  • react-qr-code:

    QRコードの生成(react-qr-code

    import React from 'react';
    import QRCode from 'react-qr-code';
    
    const App = () => (
      <div>
        <h1>QRコード生成</h1>
        <QRCode value="https://example.com" size={128} />
      </div>
    );
    
    export default App;
    

選び方: jsqr vs qr-image vs qr.js vs qrious vs react-qr-code

  • jsqr:

    画像からQRコードを読み取る必要がある場合は、jsqrを選択してください。特に、カメラや画像からQRコードを解析する機能が必要なアプリケーションに適しています。

  • qr-image:

    サーバーサイドでQRコードを生成し、PNGやSVG形式で出力する必要がある場合は、qr-imageを選択してください。Node.js環境でのQRコード生成に最適です。

  • qr.js:

    クライアントサイドでシンプルにQRコードを生成したい場合は、qr.jsを選択してください。軽量で使いやすく、基本的なQRコード生成機能を提供します。

  • qrious:

    QRコードのデザインやサイズをカスタマイズしたい場合は、qriousを選択してください。Canvasを使用して高品質なQRコードを生成できるため、デザインにこだわるアプリケーションに適しています。

  • react-qr-code:

    Reactアプリケーション内でQRコードを生成したい場合は、react-qr-codeを選択してください。Reactコンポーネントとして簡単に統合でき、動的なQRコード生成が可能です。

jsqr のREADME

jsQR

Build Status

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.

Demo

Installation

NPM

Available on npm. Can be used in a Node.js program or with a module bundler such as Webpack or Browserify.

npm install jsqr --save
// ES6 import
import jsQR from "jsqr";

// CommonJS require
const jsQR = require("jsqr");

jsQR(...);

Browser

Alternatively for frontend use jsQR.js can be included with a script tag

<script src="jsQR.js"></script>
<script>
  jsQR(...);
</script>

A note on webcams

jsQR is designed to be a completely standalone library for scanning QR codes. By design it does not include any platform specific code. This allows it to just as easily scan a frontend webcam stream, a user uploaded image, or be used as part of a backend Node.js process.

If you want to use jsQR to scan a webcam stream you'll need to extract the ImageData from the video stream. This can then be passed to jsQR. The jsQR demo contains a barebones implementation of webcam scanning that can be used as a starting point and customized for your needs. For more advanced questions you can refer to the getUserMedia docs or the fairly comprehensive webRTC sample code, both of which are great resources for consuming a webcam stream.

Usage

jsQR exports a method that takes in 3 arguments representing the image data you wish to decode. Additionally can take an options object to further configure scanning behavior.

const code = jsQR(imageData, width, height, options?);

if (code) {
  console.log("Found QR code", code);
}

Arguments

  • imageData - An Uint8ClampedArray of RGBA pixel values in the form [r0, g0, b0, a0, r1, g1, b1, a1, ...]. As such the length of this array should be 4 * width * height. This data is in the same form as the ImageData interface, and it's also commonly returned by node modules for reading images.
  • width - The width of the image you wish to decode.
  • height - The height of the image you wish to decode.
  • options (optional) - Additional options.
    • inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst) - Should jsQR attempt to invert the image to find QR codes with white modules on black backgrounds instead of the black modules on white background. This option defaults to attemptBoth for backwards compatibility but causes a ~50% performance hit, and will probably be default to dontInvert in future versions.

Return value

If a QR is able to be decoded the library will return an object with the following keys.

  • binaryData - Uint8ClampedArray - The raw bytes of the QR code.
  • data - The string version of the QR code data.
  • chunks - The QR chunks.
  • version - The QR version.
  • location - An object with keys describing key points of the QR code. Each key is a point of the form {x: number, y: number}. Has points for the following locations.
    • Corners - topRightCorner/topLeftCorner/bottomRightCorner/bottomLeftCorner;
    • Finder patterns - topRightFinderPattern/topLeftFinderPattern/bottomLeftFinderPattern
    • May also have a point for the bottomRightAlignmentPattern assuming one exists and can be located.

Because the library is written in typescript you can also view the type definitions to understand the API.

Contributing

jsQR is written using typescript. You can view the development source in the src directory.

Tests can be run with

npm test

Besides unit tests the test suite contains several hundred images that can be found in the /tests/end-to-end/ folder.

Not all the images can be read. In general changes should hope to increase the number of images that read. However due to the nature of computer vision some changes may cause images that pass to start to fail and visa versa. To update the expected outcomes run npm run-script generate-test-data. These outcomes can be evaluated in the context of a PR to determine if a change improves or harms the overall ability of the library to read QR codes. A summary of which are passing and failing can be found at /tests/end-to-end/report.json

After testing any changes, you can compile the production version by running

npm run-script build

Pull requests are welcome! Please create seperate branches for seperate features/patches.