npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teckel/vue-barcode-reader

v1.1.8

Published

Vue 3 Barcodes and QR Codes Scanner

Downloads

1,018

Readme

Vue 3 Barcode and QR Code Camera Scanner and Image Reader

A Vue.js set of components to scan barcodes and QR codes (or upload images).

Enhancements

The following bug fixes, features & improvements over the abandoned package by olefirenko

  • Uses latest version of the ZXing library which greatly increases scanning speed and compatibility.
  • On startup, searches all available rear-facing cameras to find the most ideal camera for barcode scanning, preferably one with torch (flash) and autofocus. Also saves this ideal camera to local storage for faster startup on repeat scans.
  • Adds option to activate the torch (camera flash), which can yield higher barcode scanning speed and accuracy (Android only).
  • Adds option to cycle through the available cameras (if more than one camera is available).
  • Adds option to set orientation to landscape mode, this can also increase the scanning speed and accuracy as there's more horizontal pixels in the landscape orientation.
  • Adds option to control the camera zoom (if camera device reports the user is allowed to set the zoom).
  • Adds option to switch between autofocus and manual focus mode (defaults to autofocus mode if available).
  • Adds option to set the focus distance (if in manual focus mode and camera device supports the feature).
  • Adds option to only select from rear-facing cameras (you probably only want rear-facing cameras when scanning barcodes).
  • Adds option to control the time between decode scans (defaults to 500ms).

Benefits

  • Scans multiple 1D barcode formats and 2D QR Codes.
  • Uses ZXing ("zebra crossing"), an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.

Demo

Demo | Demo repository

Installation

The easiest way to use Vue Barcode Reader is to install it with npm or yarn.

npm install @teckel/vue-barcode-reader --save

Or

yarn add @teckel/vue-barcode-reader

Usage

The Vue Barcode Reader works out of the box by just including it.

Scanning from Video Camera

Once a stream from the users camera is loaded, it's displayed and continuously scanned for barcodes. Results are indicated by the decode event.

Composition API example:

<script setup>
import { ref } from 'vue'
import { StreamBarcodeReader } from '@teckel/vue-barcode-reader'

const decodedText = ref('')

const onDecode = (result) => {
  decodedText = result
}

const onLoaded = () => {
  console.log('loaded')
}
</script>

<template>
  <StreamBarcodeReader
    torch
    no-front-cameras
    @decode="onDecode"
    @loaded="onLoaded"
  />
  <h2>Decoded value: {{ decodedText }}</h2>
</template>

Options API example:

<template>
  <StreamBarcodeReader
    torch
    no-front-cameras
    @decode="onDecode"
    @loaded="onLoaded"
  />
  <h2>Decoded value: {{ decodedText }}</h2>
</template>

<script>
import { StreamBarcodeReader } from '@teckel/vue-barcode-reader'

export default {
  components: { StreamBarcodeReader },
  data() {
    return {
      decodedText: '',
    }
  },
  methods: {
    onDecode(result) {
      this.decodedText = result
    },
    onLoaded() {
      console.log('loaded')
    },
  }
}
</script>

Scanning from Image

The component renders to a simple file picker input element. Clicking opens a file dialog. On supporting mobile devices the camera is started to take a picture. The selected images are directly scanned and positive results are indicated by the decode event.

import { ImageBarcodeReader } from '@teckel/vue-barcode-reader'

In your template you can use this syntax:

<ImageBarcodeReader
  @decode="onDecode"
  @error="onError"
/>

Props

Props will only work if the camera reports that the feature is supported. Some camera devices and some platforms either don't allow setting constraints or don't report the feature exists. Chrome on Android work quite well, while (as expected) iOS and Safari don't support most/all features.

torch

Activate the torch (flash). Can be set with simply torch or controlled via :torch="torch".

zoom

Set the zoom value (min/max/step available in hasZoom emitted value).

landscape

Set the browser to landscape orientation. In order to set landscape mode, the browser will first switch to fullscreen mode (this is required to force landscape mode).

autofocus

Defaults to true, but setting :autofocus="false" turns off autofocus (manual focus).

focus-distance

Must have :autofocus="false" (turning off autofocus and turning on manual focus) for focus-distance to work.

Set the focus distance (min/max/step available in hasFocusDistance emitted value).

no-front-cameras

Only selects from rear-facing cameras. This only works if the device reports the camera's orientation.

device-index

Select the index of the camera device to use (get the camera device array from the videoDevices emitted value).

msBetweenDecoding

Set the time between decode scans (defaults to 500ms). This is useful if you want to limit the number of scans per second (for example, if you're scanning a barcode on a moving object, you may want to limit the number of scans per second).

Emitted values

hasTorch

Returns true or false if camera device reports it's capable of activating the torch (flash).

hasAutofocus

Returns true or false if camera device reports it's capable of autofocus mode.

hasZoom

Returns false or object containing min, max, step set from the supported camera device.

hasFocusDistance

Returns false or object containing min, max, step set from the supported camera device.

videoDevices

Returns an array of camera devices available to the browser (can be used to select the desired camera device via device-index prop).

cameraDetails

Object dump of the library processing to select the ideal camera, switch cameras, and apply constraints (useful for debugging or could be used for enhanced features).

Events

loaded

When the library is loaded and the camera is ready to scan

decode

When a barcode or QR code is scanned. The result is passed as a parameter to the event handler. The result is the text encoded in the barcode or QR code.

result

When a barcode or QR code is scanned. The result is passed as a parameter to the event handler. Below is an example result object from the UPC code of a box of Kellogg's Frosted Mini-Wheats:

{
    "text": "038000199349",
    "rawBytes": null,
    "numBits": 0,
    "resultPoints": [
        {
            "x": 189,
            "y": 240
        },
        {
            "x": 445.5,
            "y": 240
        }
    ],
    "format": 14,
    "timestamp": 1690401753332,
    "resultMetadata": null
}

Barcode formats (from above JSON object format):

  • 0 Aztec
  • 1 Codabar
  • 2 Code 39
  • 3 Code 93
  • 4 Code 128
  • 5 Data Matrix
  • 6 EAN-8
  • 7 EAN-13
  • 8 ITF
  • ~~9 MaxiCode~~ (not supported)
  • 10 PDF 417
  • 11 QR Code
  • 12 RSS-14
  • ~~13 RSS-Expanded~~ (not supported)
  • 14 UPC-A
  • 15 UPC-E
  • 16 UPC-EAN Extension