Scan Html to Read Status of Button From Js

Html5-QRCode

(supports barcodes now :))

A cross-platform HTML5 QR lawmaking & barcode reader.

Use this lightweight library to easily / apace integrate QR lawmaking, bar code, and other mutual code scanning capabilities to your web application.

  • Supports easy scanning using an integrated webcam or camera in smartphones (Android / IOS).

  • Supports scanning codes from files or default cameras on smartphones.

  • Recently Added Supports bar lawmaking scanning in various formats.

  • Supports two kinds of APIs

    • Html5QrcodeScanner — Terminate-to-end scanner with UI, integrate with less than ten lines of code.
    • Html5Qrcode — Powerful set of APIs you lot tin utilise to build your UI without worrying about camera setup, handling permissions, reading codes, etc.

Support for scanning local files on the device is a new addition and helpful for the web browser which does not back up inline spider web-photographic camera admission in smartphones. Annotation: This doesn't upload files to any server — everything is done locally.

Build Status GitHub issues GitHub tag (latest by date) GitHub Codacy Badge Gitter

GitHub all releases npm

Demo at scanapp.org Demo at qrcode.minhazav.dev - Scanning different types of codes

Notice

UX/UXD/UXR assist wanted: We are looking to meliorate user experience of this code scanning library — if you are interested in making this experience better for both developers and finish users, delight share your ideas, thoughts, inputs in this discussion

Supported platforms

We are working continuously on adding back up for more and more than platforms. If y'all notice a platform or a browser where the library is not working, please feel costless to file an issue. Check the demo link to test it out.

Legends

PC / Mac

Firefox
Firefox
Chrome
Chrome
Safari
Safari
Opera
Opera
Edge
Border

Android

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Opera
Opera
Opera-Mini
Opera Mini
UC
UC

IOS

Safari
Safari
Chrome
Chrome
Firefox
Firefox
Edge
Border
* *

* Supported for IOS versions >= 15.1

Earlier version 15.one, Webkit for IOS is used past Chrome, Firefox, and other browsers in IOS and they do non accept webcam permissions still. There is an ongoing issue on fixing the support for iOS - effect/14

Framework support

The library can be easily used with several other frameworks, I have been adding examples for a few of them and would continue to add together more.

Html5 VueJs ElectronJs React

Supported Code formats

Code scanning is dependent on Zxing-js library. We volition be working on top of it to add together support for more than types of code scanning. If you feel a certain blazon of lawmaking would be helpful to have, please file a feature request.

Code Instance
QR Code
AZTEC
CODE_39
CODE_93
CODE_128
ITF
EAN_13
EAN_8
PDF_417
UPC_A
UPC_E
DATA_MATRIX
MAXICODE*
RSS_14*
RSS_EXPANDED*

*Formats are not supported past our experimental integration with native BarcodeDetector API integration (Read more).

Description - View Demo

See an terminate to finish scanner experience at scanapp.org.

This is a cross-platform JavaScript library to integrate QR code, bar codes & a few other types of code scanning capabilities to your applications running on HTML5 uniform browser.

Supports:

  • Querying camera on the device (with user permissions)
  • Rendering live photographic camera feed, with easy to use user interface for scanning
  • Supports scanning a different kind of QR codes, bar codes and other formats
  • Supports selecting image files from the device for scanning codes

How to use

For full information read this commodity.

Download the script from release page or install using npm with:

Add an element you lot want to employ as a placeholder for QR Code scanner

              <              div              id="reader"              width="600px">              </              div              >            

Ideally practice not set the height of this container as the height should depend on the acme of the video feed from the camera. The library would honor the existing width, otherwise employ the default width. The summit is derived from the aspect ratio of the video feed.

Using straight in browser without any loader

If you are non using whatsoever loader, you can become the latest UMD javascript lawmaking in production from https://unpkg.com/html5-qrcode.

              <              script              src="https://unpkg.com/html5-qrcode"              type="text/javascript">            

In case y'all installed the plugin using npm but notwithstanding use javascript without any module loader, yous can get the minified script in node_modules/html5-qrcode/html5-qrcode.min.js

Using with module loaders

Include the script with

              // To employ Html5QrcodeScanner (more than info below)              import              {              Html5QrcodeScanner              }              from              "html5-qrcode"              // To use Html5Qrcode (more info below)              import              {              Html5Qrcode              }              from              "html5-qrcode"            

Easy Fashion - With terminate to end scanner user interface

Html5QrcodeScanner lets you implement an end to end scanner with few lines of lawmaking with the default user interface which allows scanning using the camera or selecting an paradigm from the file arrangement.

You tin can set up the scanner as follows:

              function              onScanSuccess              (              decodedText              ,              decodedResult              )              {              // handle the scanned lawmaking as you like, for example:              console              .              log              (              `Code matched =                                  ${                  decodedText                  }                `              ,              decodedResult              )              ;              }              function              onScanFailure              (              error              )              {              // handle scan failure, normally better to ignore and keep scanning.              // for example:              console              .              warn              (              `Code browse error =                                  ${                  error                  }                `              )              ;              }              let              html5QrcodeScanner              =              new              Html5QrcodeScanner              (              "reader"              ,              {              fps:              10              ,              qrbox:              {              width:              250              ,              elevation:              250              }              }              ,              /* verbose= */              simulated              )              ;              html5QrcodeScanner              .              render              (              onScanSuccess              ,              onScanFailure              )              ;            

Pro Mode - if you want to implement your own user interface

Y'all tin can use Html5Qrcode class to set your QR code scanner (with your own user interface) and allow users to scan QR codes using the camera or by choosing an epitome file in the file organisation or native cameras in smartphones.

Yous tin use the following APIs to fetch camera, start scanning and stop scanning.

For using inline QR Code scanning with Webcam or Smartphone camera

Starting time Scanning

To become a list of supported cameras, query it using static method Html5Qrcode.getCameras(). This method returns a Promise with a list of devices supported in format { id: "id", label: "label" }.

              // This method will trigger user permissions              Html5Qrcode              .              getCameras              (              )              .              so              (              devices              =>              {              /**                              * devices would exist an array of objects of type:                              * { id: "id", characterization: "label" }                              */              if              (              devices              &&              devices              .              length              )              {              var              cameraId              =              devices              [              0              ]              .              id              ;              // .. utilize this to showtime scanning.              }              }              )              .              take hold of              (              err              =>              {              // handle err              }              )              ;            

Of import: Annotation that this method will trigger user permission if the user has not granted information technology already.

Alert: Direct access to the photographic camera is a powerful feature. It requires consent from the user, and your site MUST exist on a secure origin (HTTPS).

Alarm: Asking for access to the camera on page load will consequence in most of your users rejecting access to it. More info

In one case you accept the camera ID from device.id, start camera using Html5Qrcode#kickoff(..). This method returns a Hope with Qr code scanning initiation.

              const              html5QrCode              =              new              Html5Qrcode              (              /* chemical element id */              "reader"              )              ;              html5QrCode              .              start              (              cameraId              ,              {              fps:              10              ,              // Optional, frame per seconds for qr code scanning              qrbox:              {              width:              250              ,              height:              250              }              // Optional, if you want bounded box UI              }              ,              (              decodedText              ,              decodedResult              )              =>              {              // do something when code is read              }              ,              (              errorMessage              )              =>              {              // parse mistake, ignore information technology.              }              )              .              catch              (              (              err              )              =>              {              // Get-go failed, handle it.              }              )              ;            

You tin can optionally set another statement in constructor called verbose to print all logs to console

              const              html5QrCode              =              new              Html5Qrcode              (              "reader"              ,              /* verbose= */              truthful              )              ;            
Scanning without cameraId

In mobile devices you may want users to directly browse the QR code using the back camera or the front camera for some use cases. For such cases you can avoid using the exact camera device ID that you go from Html5Qrcode.getCameras(). The start() method allows passing constraints in identify of camera device ID similar to html5 web API syntax. You can commencement scanning similar mentioned in these examples:

              const              html5QrCode              =              new              Html5Qrcode              (              "reader"              )              ;              const              qrCodeSuccessCallback              =              (              decodedText              ,              decodedResult              )              =>              {              /* handle success */              }              ;              const              config              =              {              fps:              10              ,              qrbox:              {              width:              250              ,              superlative:              250              }              }              ;              // If y'all desire to adopt forepart camera              html5QrCode              .              showtime              (              {              facingMode:              "user"              }              ,              config              ,              qrCodeSuccessCallback              )              ;              // If y'all want to prefer back camera              html5QrCode              .              start              (              {              facingMode:              "environment"              }              ,              config              ,              qrCodeSuccessCallback              )              ;              // Select front photographic camera or neglect with `OverconstrainedError`.              html5QrCode              .              showtime              (              {              facingMode:              {              exact:              "user"              }              }              ,              config              ,              qrCodeSuccessCallback              )              ;              // Select back photographic camera or fail with `OverconstrainedError`.              html5QrCode              .              start              (              {              facingMode:              {              exact:              "environment"              }              }              ,              config              ,              qrCodeSuccessCallback              )              ;            

Passing the cameraId (recommended approach) is similar to

              html5QrCode              .              start              (              {              deviceId:              {              exact:              cameraId              }              }              ,              config              ,              qrCodeSuccessCallback              )              ;            
Stop Scanning

To finish using camera and thus stop scanning, call Html5Qrcode#stop() which returns a Promise for stopping the video feed and scanning.

              html5QrCode              .              cease              (              )              .              then              (              (              ignore              )              =>              {              // QR Lawmaking scanning is stopped.              }              )              .              catch              (              (              err              )              =>              {              // Stop failed, handle it.              }              )              ;            

Note that the class is stateful and stop() should be called to properly tear down the video and camera objects safely later calling starting time() when the scan is over or the user intend to motility on. terminate() will stop the video feed on the viewfinder.

For QR Code scanning using local files or inbuilt camera on Smartphones

Selector in Android Selector in IOS
Taken on Pixel 3, Google Chrome
Taken on iPhone vii, Google Chrome

You can alternatively leverage QR Code scanning for local files on the device or default photographic camera on the device. It works similar to inline QR Code scanning.

Define the HTML container and import the JavaScript library as mentioned above

              <              div              id="reader"              width="600px"              elevation="600px">              </              div              >              <              script              src="./dist/html5-qrcode.js">              </              script              >            

Information technology's non mandatory to set the acme and width of the HTML element. If provided, the library would try to honour it. If it's non set, the library would set a default width and derive the pinnacle based on the input epitome's attribute ratio.

Add an Input element for supporting file selection like this:

              <              input              type="file"              id="qr-input-file"              take="prototype/*">              <!--                                            Or add captured if yous just want to enable smartphone camera, PC browsers will ignore it.              -->              <              input              type="file"              id="qr-input-file"              take="image/*"              capture              >            

Find more data about this at developers.google.com.

And in JavaScript lawmaking initialize the object and attach listener similar this:

              const              html5QrCode              =              new              Html5Qrcode              (              /* element id */              "reader"              )              ;              // File based scanning              const              fileinput              =              document              .              getElementById              (              'qr-input-file'              )              ;              fileinput              .              addEventListener              (              'change'              ,              e              =>              {              if              (              due east              .              target              .              files              .              length              ==              0              )              {              // No file selected, ignore                            return              ;              }              const              imageFile              =              e              .              target              .              files              [              0              ]              ;              // Browse QR Code              html5QrCode              .              scanFile              (              imageFile              ,              truthful              )              .              then              (              decodedText              =>              {              // success, utilize decodedText              panel              .              log              (              decodedText              )              ;              }              )              .              catch              (              err              =>              {              // failure, handle it.              console              .              log              (              `Error scanning file. Reason:                                  ${                  err                  }                `              )              }              )              ;              }              )              ;              // Notation: Current public API `scanFile` only returns the decoded text. At that place is              // another work in progress API (in beta) which returns a full decoded result of              // type `QrcodeResult` (bank check interface in src/core.ts) which contains the              // decoded text, code format, lawmaking premises, etc.              // Eventually, this beta API will be migrated to the public API.            

Note that inline scanning and file-based scanning are mutually sectional at the moment. This means you tin merely use one of them at a time. I'll soon be adding support for the choice to accept both if the requirement comes in. If you want to utilize both, use html5QrCode#clear() method to clear the sheet.

Demo


Browse this image or visit blog.minhazav.dev/enquiry/html5-qrcode.html

For more data

Check these articles on how to utilise this library:

  • QR and barcode scanner using HTML and JavaScript
  • HTML5 QR Code scanning — launched v1.0.i without jQuery dependency and refactored Promise based APIs.
  • HTML5 QR Lawmaking scanning with JavaScript — Support for scanning the local file and using default camera added (v1.0.5)

Screenshots

screenshot
Figure: Screenshot from Google Chrome running on MacBook Pro

Documentation

Post-obit methods are available in this library (typescript definition)

              /** Camera Device interface. */              interface              CameraDevice              {              id:              cord              ;              label:              string              ;              }              /** Different states of scanner */              enum              Html5QrcodeScannerState              {              // Indicates the sanning is not running or user is using file based              // scanning.              NOT_STARTED              =              0              ,              // Camera scan is running.              SCANNING              ,              // Camera scan is paused but photographic camera is running.              PAUSED              ,              }              /**                              * Code formats supported by this library.                              */              enum              Html5QrcodeSupportedFormats              {              QR_CODE              =              0              ,              AZTEC              ,              CODABAR              ,              CODE_39              ,              CODE_93              ,              CODE_128              ,              DATA_MATRIX              ,              MAXICODE              ,              ITF              ,              EAN_13              ,              EAN_8              ,              PDF_417              ,              RSS_14              ,              RSS_EXPANDED              ,              UPC_A              ,              UPC_E              ,              UPC_EAN_EXTENSION              ,              }              /** Defines dimension for QR Code Scanner. */              interface              QrDimensions              {              width:              number              ;              height:              number              ;              }              /**                              * A part that takes in the width and height of the video stream                                            * and returns QrDimensions.                              *                                            * Viewfinder refers to the video showing photographic camera stream.                              */              type              QrDimensionFunction              =              (              viewfinderWidth:              number              ,              viewfinderHeight:              number              )              =>              QrDimensions              ;              /** Format of detected code. */              class              QrcodeResultFormat              {              public              readonly              format:              Html5QrcodeSupportedFormats              ;              public              readonly              formatName:              cord              ;              }              /** Detailed scan upshot. */              interface              QrcodeResult              {              /** Decoded text. */              text:              cord              ;              /** Format that was successfully scanned. */              format?:              QrcodeResultFormat              ,              }              /** QrCode result object. */              interface              Html5QrcodeResult              {              decodedText:              cord              ;              outcome:              QrcodeResult              ;              }              /** Type for a callback for a successful lawmaking browse. */              type              QrcodeSuccessCallback              =              (              decodedText:              cord              ,              result:              Html5QrcodeResult              )              =>                              void                            ;              /** Type for a callback for failure during code scan. */              type              QrcodeErrorCallback              =              (              errorMessage:              string              ,              fault:              Html5QrcodeError              )              =>                              void                            ;              /**                              * Interface for configuring {@course                Html5Qrcode} class case.                              */              interface              Html5QrcodeConfigs              {              /**                              * Array of formats to support of type {@type                Html5QrcodeSupportedFormats}.                              */              formatsToSupport:              Assortment              <              Html5QrcodeSupportedFormats              >              |              undefined              ;              }              /** Configuration for creating {@class                Html5Qrcode}. */              interface              Html5QrcodeFullConfig              extends              Html5QrcodeConfigs              {              /**                              * If true, all logs would be printed to console. Faux by default.                              */              verbose:              boolean              |              undefined              ;              }              interface              Html5QrcodeCameraScanConfig              {              /**                              * Optional, Expected framerate of QR code scanning. example { fps: two } ways the                              * scanning would be done every 500 ms.                              */              fps:              number              |              undefined              ;              /**                              * Optional, edge size, dimension or calculator function for QR scanning                              * box, the value or computed value should exist smaller than the width and                              * height of the full region.                              *                                            * This would make the scanner await like this:                              *          ----------------------                              *          |********************|                              *          |******,,,,,,,,,*****|      <--- shaded region                              *          |******|       |*****|      <--- not shaded region would be                              *          |******|       |*****|          used for QR code scanning.                              *          |******|_______|*****|                              *          |********************|                              *          |********************|                              *          ----------------------                              *                                            * Instance of {@interface                QrDimensions} can exist passed to construct a non                              * square rendering of scanner box. You lot can also pass in a role of blazon                              * {@type                QrDimensionFunction} that takes in the width and height of the                              * video stream and return QR box size of type {@interface                QrDimensions}.                              *                                            * If this value is not ready, no shaded QR box will be rendered and the scanner                              * volition scan the entire area of video stream.                              */              qrbox?:              number              |              QrDimensions              |              QrDimensionFunction              |              undefined              ;              /**                              * Optional, Desired aspect ratio for the video feed. Ideal aspect ratios                              * are four:3 or 16:9. Passing very incorrect attribute ratio could lead to video feed                              * not showing up.                              */              aspectRatio?:              number              |              undefined              ;              /**                              * Optional, if {@code                true} flipped QR Code won't be scanned. Only utilise this                              * if you lot are sure the camera cannot give mirrored feed if yous are facing                              * performance constraints.                              */              disableFlip?:              boolean              |              undefined              ;              /*                              * Optional, @beta(this config is not well supported yet).                              *                              * Important: When passed this will override other parameters like                              * 'cameraIdOrConfig' or configurations like 'aspectRatio'.                              * 'videoConstraints' should exist of type {@lawmaking                MediaTrackConstraints} as                              * divers in                              * https://programmer.mozilla.org/en-Us/docs/Web/API/MediaTrackConstraints                              * and is used to specify a diverseness of video or camera controls like:                              * aspectRatio, facingMode, frameRate, etc.                              */              videoConstraints?:              MediaTrackConstraints              |              undefined              ;              }              /**                              * Interface for controlling different aspects of {@form                Html5QrcodeScanner}.                              */              interface              Html5QrcodeScannerConfig              extends              Html5QrcodeCameraScanConfig              ,              Html5QrcodeConfigs              {              /**                              * If {@lawmaking                true} the library volition call back if the camera permissions                              * were previously granted and what camera was last used. If the permissions                              * is already granted for "camera", QR lawmaking scanning will automatically                              * start for previously used camera.                              */              rememberLastUsedCamera?:              boolean              |              undefined              ;              }              ;              class              Html5Qrcode              {              /**                              * Returns a Hope with a list of all cameras supported by the device.                              */              static              getCameras              (              ):              Assortment              <              CameraDevice              >              // Returns a Hope              /**                              * Initialize QR Lawmaking scanner.                              *                                            *                @param                elementId - Id of the HTML element.                              *                @param                verbose - optional configuration object                              */              constructor              (              elementId:              string              ,              config:              Html5QrcodeFullConfig              |              undefined              )              {              }              /**                              * Start scanning QR codes or barcodes for a given camera.                              *                                            *                @param                cameraIdOrConfig Identifier of the camera, it can either be the                              *  camera id retrieved from {@code                Html5Qrcode#getCameras()} method or                              *  object with facing style constraint.                              *                @param                configuration Extra configurations to melody the code scanner.                              *                @param                qrCodeSuccessCallback Callback called when an instance of a QR                              * code or any other supported bar code is found.                              *                @param                qrCodeErrorCallback Callback chosen in cases where no instance of                              * QR code or whatever other supported bar code is found.                              */              outset              (              cameraIdOrConfig:              Html5QrcodeIdentifier              ,              configuration:              Html5QrcodeCameraScanConfig              |              undefined              ,              qrCodeSuccessCallback:              QrcodeSuccessCallback              |              undefined              ,              qrCodeErrorCallback:              QrcodeErrorCallback              |              undefined              ,              ):              Promise              <              zip              >              {              }              /**                              * Pauses the ongoing browse.                              *                                            *                @param                shouldPauseVideo (Optional, default = simulated) If {@code                true} the                              * video will be paused.                              *                                            *                @throws                error if method is called when scanner is not in scanning land.                              */              pause              (              shouldPauseVideo?:              boolean              )              ;              /**                              * Resumes the paused scan.                              *                                            * If the video was previously paused by setting {@code                shouldPauseVideo}                              * to {@code                true} in {@link                Html5Qrcode#pause(shouldPauseVideo)}, calling                              * this method will resume the video.                              *                              * Note: with this caller volition commencement getting results in success and error                              * callbacks.                              *                                            *                @throws                error if method is called when scanner is not in paused state.                              */              resume              (              )              ;              /**                              * Stops streaming QR Lawmaking video and scanning.                                            */              stop              (              ):              Promise              <                              void                            >              {              }              /**                              * Gets country of the camera scan.                              *                              *                @returns                state of type {@enum                ScannerState}.                              */              getState              (              ):              Html5QrcodeScannerState              ;              /**                              * Scans an Image File for QR Code.                              *                              * This feature is mutually sectional to camera-based scanning, you should                              * call end() if the camera-based scanning was ongoing.                              *                              *                @param                imageFile a local file with Image content.                              *                @param                showImage if true, the Image will be rendered on given element.                              *                              *                @returns                Promise with decoded QR lawmaking string on success.                              */              scanFile              (              imageFile:              File              ,              /* default=true */              showImage:              boolean              |              undefined              ):              Promise              <              cord              >              {              }              /**                              * Clears the existing canvas.                              *                                            * Note: in case of ongoing web-cam based browse, it needs to be explicitly                              * closed earlier calling this method, else it will throw an exception.                              */              clear              (              ):                              void                            {              }              // Returns void              }              class              Html5QrcodeScanner              {              /**                              * Creates an example of this class.                              *                              *                @param                elementId Id of the HTML element.                              *                @param                config Actress configurations to tune the code scanner.                              *                @param                verbose - If true, all logs would be printed to console.                                            */              constructor              (              elementId:              cord              ,              config:              Html5QrcodeScannerConfig              |              undefined              ,              verbose:              boolean              |              undefined              )              {              }              /**                              * Renders the User Interface.                              *                                            *                @param                qrCodeSuccessCallback Callback called when an instance of a QR                              * lawmaking or whatever other supported bar code is found.                              *                @param                qrCodeErrorCallback optional callback called in cases where no                              * instance of QR code or any other supported bar code is plant.                              */              render              (              qrCodeSuccessCallback:              QrcodeSuccessCallback              ,              qrCodeErrorCallback:              QrcodeErrorCallback              |              undefined              )              {              }              /**                              * Pauses the ongoing browse.                              *                                            * Notes:                              * -   Should simply exist chosen if camera scan is ongoing.                              *                              *                @param                shouldPauseVideo (Optional, default = false) If {@code                true}                              * the video will be paused.                              *                                            *                @throws                error if method is called when scanner is not in scanning country.                              */              pause              (              shouldPauseVideo?:              boolean              )              ;              /**                              * Resumes the paused scan.                              *                                            * If the video was previously paused by setting {@code                shouldPauseVideo}                              * to {@code                truthful} in {@link                Html5QrcodeScanner#intermission(shouldPauseVideo)},                              * calling this method will resume the video.                              *                              * Notes:                              * -   Should only be chosen if camera scan is ongoing.                              * -   With this caller will start getting results in success and error                              * callbacks.                              *                                            *                @throws                error if method is chosen when scanner is not in paused state.                              */              resume              (              )              ;              /**                              * Gets land of the camera browse.                              *                              *                @returns                state of blazon {@enum                Html5QrcodeScannerState}.                              */              getState              (              ):              Html5QrcodeScannerState              ;              /** Removes the QR Lawmaking scanner UI. */              articulate              (              ):              Hope              <                              void                            >              {              }              }            

Extra optional configuration in kickoff() method

Configuration object that can be used to configure both the scanning beliefs and the user interface (UI). Most of the fields take default properties that will exist used unless a different value is provided. If you exercise not want to override anything, you can just pass in an empty object {}.

fps — Integer, Case = ten

A.K.A frame per second, the default value for this is 2, but it can exist increased to get faster scanning. Increasing besides high value could affect performance. Value >yard will simply fail.

qrboxQrDimensions or QrDimensionFunction (Optional), Example = { width: 250, height: 250 }

Use this holding to limit the region of the viewfinder you want to use for scanning. The rest of the viewfinder would be shaded. For example, past passing config { qrbox : { width: 250, pinnacle: 250 } }, the screen volition await like:

This can exist used to set a rectangular scanning area with config like:

              let              config              =              {              qrbox              :              {              width:              400              ,              superlative:              150              }              }            

This config likewise accepts a function of blazon

              /**                              * A office that takes in the width and height of the video stream                            * and returns QrDimensions.              *                            * Viewfinder refers to the video showing camera stream.              */              type              QrDimensionFunction              =              (              viewfinderWidth:              number              ,              viewfinderHeight:              number              )              =>              QrDimensions              ;            

This allows you to set dynamic QR box dimensions based on the video dimensions. See this web log article for example: Setting dynamic QR box size in Html5-qrcode - ScanApp blog

This might be desirable for bar code scanning.

If this value is not ready, no shaded QR box will be rendered and the scanner will scan the entire area of video stream.

aspectRatio — Bladder, Example 1.777778 for xvi:ix aspect ratio

Use this property to render the video feed in a certain aspect ratio. Passing a nonstandard aspect ratio like 100000:i could lead to the video feed not even showing upward. Ideal values tin can be:

Value Attribute Ratio Use Example
1.333334 iv:3 Standard photographic camera aspect ratio
1.777778 16:ix Full screen, cinematic
1.0 1:1 Square view

If you do not pass any value, the whole viewfinder would be used for scanning. Note: this value has to be smaller than the width and height of the QR code HTML element.

disableFlip — Boolean (Optional), default = imitation

By default, the scanner tin can scan for horizontally flipped QR Codes. This also enables scanning QR lawmaking using the front end camera on mobile devices which are sometimes mirrored. This is false past default and I recommend changing this but if:

  • Yous are sure that the photographic camera feed cannot be mirrored (Horizontally flipped)
  • Yous are facing performance problems with this enabled.

Here's an example of a normal and mirrored QR Lawmaking

Normal QR Code Mirrored QR Code

rememberLastUsedCamera — Boolean (Optional), default = truthful

If true the last photographic camera used past the user and weather or not permission was granted would be remembered in the local storage. If the user has previously granted permissions — the request permission option in the UI will be skipped and the final selected photographic camera would be launched automatically for scanning.

If true the library shall remember if the camera permissions were previously granted and what camera was last used. If the permissions is already granted for "camera", QR code scanning will automatically * showtime for previously used photographic camera.

Scanning just specific formats

By default, both camera stream and image files are scanned against all the supported lawmaking formats. Both Html5QrcodeScanner and Html5Qrcode classes can be configured to but support a subset of supported formats. Supported formats are defined in enum Html5QrcodeSupportedFormats.

              enum              Html5QrcodeSupportedFormats              {              QR_CODE              =              0              ,              AZTEC              ,              CODABAR              ,              CODE_39              ,              CODE_93              ,              CODE_128              ,              DATA_MATRIX              ,              MAXICODE              ,              ITF              ,              EAN_13              ,              EAN_8              ,              PDF_417              ,              RSS_14              ,              RSS_EXPANDED              ,              UPC_A              ,              UPC_E              ,              UPC_EAN_EXTENSION              ,              }            

I recommend using this only if you need to explicitly omit support for certain formats or want to reduce the number of scans done per second for performance reasons.

Scanning only QR code with Html5Qrcode

              const              html5QrCode              =              new              Html5Qrcode              (              "reader"              ,              {              formatsToSupport:              [              Html5QrcodeSupportedFormats              .              QR_CODE              ]              }              )              ;              const              qrCodeSuccessCallback              =              (              decodedText              ,              decodedResult              )              =>              {              /* handle success */              }              ;              const              config              =              {              fps:              10              ,              qrbox:              {              width:              250              ,              height:              250              }              }              ;              // If yous want to prefer front camera              html5QrCode              .              beginning              (              {              facingMode:              "user"              }              ,              config              ,              qrCodeSuccessCallback              )              ;            

Scanning just QR code and UPC codes with Html5QrcodeScanner

              function              onScanSuccess              (              decodedText              ,              decodedResult              )              {              // Handle the scanned code equally you like, for instance:              console              .              log              (              `Code matched =                                  ${                  decodedText                  }                `              ,              decodedResult              )              ;              }              const              formatsToSupport              =              [              Html5QrcodeSupportedFormats              .              QR_CODE              ,              Html5QrcodeSupportedFormats              .              UPC_A              ,              Html5QrcodeSupportedFormats              .              UPC_E              ,              Html5QrcodeSupportedFormats              .              UPC_EAN_EXTENSION              ,              ]              ;              const              html5QrcodeScanner              =              new              Html5QrcodeScanner              (              "reader"              ,              {              fps:              10              ,              qrbox:              {              width:              250              ,              height:              250              }              ,              formatsToSupport:              formatsToSupport              }              ,              /* verbose= */              imitation              )              ;              html5QrcodeScanner              .              render              (              onScanSuccess              )              ;            

Experimental features

The library now supports some experimental features which are supported in the library but not recommended for production usage either due to express testing done or limited compatibility for underlying APIs used. Read more than about information technology here. Some experimental features include:

  • Support for BarcodeDetector JavaScript API

How to change and build

  1. Code changes should only exist made to /src only.

  2. Run npm install to install all dependencies.

  3. Run npm run-script build to build JavaScript output. The output JavaScript distribution is built to /dist/html5-qrcode.min.js. If you are developing on Windows OS, run npm run-script build-windows.

  4. Testing

    • Run npm test
    • Run the tests before sending a pull request, all tests should run.
    • Please add tests for new behaviors sent in PR.
  5. Ship a pull request

    • Include lawmaking changes but to ./src. Practise not modify ./dist manually.
    • In the pull request add together a comment like
                      @all-contributors delight add together @mebjas for this new characteristic or tests                                  
    • For calling out your contributions, the bot volition update the contributions file.
    • Code volition be built & published by the author in batches.

How to contribute

You tin can contribute to the projection in several means:

  • File issue ticket for any observed problems or compatibility consequence with the project.
  • File feature asking for missing features.
  • Accept open bugs or characteristic asking and work on it and transport a Pull Asking.
  • Write unit tests for existing codebase (which is not covered by tests today). Assistance wanted on this - read more than.

Support 💖

This projection would not be possible without all of our fantastic contributors and sponsors. If you'd similar to support the maintenance and upkeep of this projection yous tin donate via GitHub Sponsors.

And huge thanks to post-obit organizations for non monitery sponsorships

Credits

The decoder used for the QR code reading is from Zxing-js https://github.com/zxing-js/library

wekeytheaver.blogspot.com

Source: https://github.com/mebjas/html5-qrcode

0 Response to "Scan Html to Read Status of Button From Js"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel