Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Javascript QR Code Scanner based on Cosmo Wolfe's javascript port of Google's ZXing library.
In this library, several improvements have been applied over the original port:
According to our benchmarking this project's scanner engine's detection rate is about 2-3 times (and up to 8 times) as high as the one of the most popular javascript QR scanner library LazarSoft/jsqrcode.
The library supports scanning a continuous video stream from a web cam as well as scanning of single images.
The development of this library is sponsored by nimiq, world's first browser based blockchain.
See https://nimiq.github.io/qr-scanner/demo/
To install via npm:
npm install --save qr-scanner
To install via yarn:
yarn add qr-scanner
Or simply copy qr-scanner.min.js
and qr-scanner-worker.min.js
to your project.
The QR Scanner consists of two files.
qr-scanner.min.js
is the main API as an es6 module and can be imported as follows:
import QrScanner from 'path/to/qr-scanner.min.js'; // if using plain es6 import
import QrScanner from 'qr-scanner'; // if installed via package and bundling with webpack or rollup
This requires the importing script to also be an es6 module or a module script tag, e.g.:
<script type="module">
import QrScanner from 'path/to/qr-scanner.min.js';
// do something with QrScanner
</script>
qr-scanner-worker.min.js
is a plain Javascript file for the separate worker thread and needs to be copied over to your project. You should then point QrScanner.WORKER_PATH
to where you put that file:
QrScanner.WORKER_PATH = 'path/to/qr-scanner-worker.min.js';
If you're using webpack to bundle your project, the file loader might be interesting for you to automatically copy the worker into your build:
import QrScannerWorkerPath from '!!file-loader!./node_modules/qr-scanner/qr-scanner-worker.min.js';
QrScannerLib.WORKER_PATH = QrScannerWorkerPath;
Create a <video>
element where the web cam video stream should get rendered:
<video></video>
const qrScanner = new QrScanner(videoElem, result => console.log('decoded qr code:', result));
As an optional third parameter a specific resolution that should be worked on can be specified. The default is 400.
Note: to read from a Web Cam stream, your page must be served via HTTPS.
QrScanner.scanImage(image)
.then(result => console.log(result))
.catch(error => console.log(error || 'No QR code found.'));
Supported image sources are: HTMLImageElement, SVGImageElement, HTMLVideoElement, HTMLCanvasElement, ImageBitmap, OffscreenCanvas, File / Blob
The scanner by default scans for dark QR codes on a bright background. You can change this behavior to scan for bright QR codes on dark background or for both at the same time:
qrScanner.setInversionMode(inversionMode);
Where inversionMode
can be original
, invert
or both
.
The default for web cam scanning is original
and for single image scanning both
.
Change the weights for red, green and blue in the grayscale computation to improve contrast for QR codes of a specific color:
qrScanner.setGrayscaleWeights(red, green, blue, useIntegerApproximation = true);
Where red
, green
and blue
should sum up to 256 if useIntegerApproximation === true
and 1
otherwise. By default, these values are used.
You can destroy the QR scanner if you don't need it anymore:
qrScanner.destroy();
qrScanner = null;
This will stop the camera stream and web worker and cleans up event listeners.
The project is prebuild in qr-scanner.min.js in combination with qr-scanner-worker.min.js. Building yourself is only necessary if you want to change the code in the /src folder. NodeJs is required for building.
Install required build packages:
npm install
Building:
npm run build
FAQs
A javascript QR scanner library
The npm package qr-scanner receives a total of 36,685 weekly downloads. As such, qr-scanner popularity was classified as popular.
We found that qr-scanner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.