1D & 2D Barcodes
This barcode utility covers two distinct use cases: generating print-ready codes from user input and scanning them live through a device camera. It targets mobile users primarily, using the MediaDevices API with a rear-camera preference and fallback logic for devices that do not support the environment facing mode.
Dynamic Barcode Generation
The generation side uses bwip-js to render directly onto an HTML5 canvas element. A BarCode component accepts the selected symbology (bcid) and input text, then re-renders via useEffect whenever either value changes. This covers the full range from simple QR codes to Code 128 and EAN-13, all following international symbology standards without additional configuration.
Real-time Camera Integration
The scanner uses BrowserMultiFormatReader from @zxing/library to decode barcodes from a live video feed. The getCameraStream function requests the rear camera via
and falls back to any available camera if the constraint is rejected. This handles the variation in camera APIs across Android browsers without requiring separate code paths.Responsive Interface and UX
The layout is built with Tailwind CSS using a mobile-first approach. The scanning viewport and the generated code occupy most of the screen on small displays. Camera errors, including NotAllowedError and NotFoundError, surface as specific messages so users know whether the problem is a permission issue or missing hardware.
Technical Challenges
The main difficulty was consistent scanning quality across Android devices with differing camera capabilities. Using
1ideal1exactLive Demo
Live DemoYou can try the web app yourself by clicking on the button. You will need to allow camera access on the reader. Note that camera performance can vary across different Android mobile browsers.
Video Demonstration
External Media Required
This video requires third-party cookies from YouTube to be displayed. Accepting will enable all external media across the site.