1D & 2D Barcodes
RepositoryI developed this comprehensive barcode utility to master advanced Next.js features and browser-based hardware integration. The project allows users to generate a wide array of 1D and 2D codes—including QR, EAN-13, and Data Matrix—while providing a robust scanning interface that leverages the device's camera. It served as a practical exploration of modern TypeScript development and real-time image processing in the browser.
Dynamic Barcode Generation
The generation engine uses the bwip-js library to render professional-grade barcodes directly onto a HTML5 canvas. I implemented a modular BarCode component that dynamically adjusts its rendering parameters based on the selected code type (bcid) and input value. This approach ensures that every generated code—whether it's a simple QR code or a complex Code 128—is perfectly scaled and follows international symbology standards.
Real-time Camera Integration
The scanning functionality leverages the BrowserMultiFormatReader from the @zxing/library. I implemented a resilient getCameraStream function that handles the complexities of mobile hardware, including requesting permissions and fallback logic for different camera lenses (e.g., forcing the environment facing mode). The reader processes the video feed in a continuous loop, identifying and decoding barcodes in real-time with high accuracy even in challenging lighting conditions.
Responsive Interface and UX
To ensure a smooth experience across devices, I used Tailwind CSS for a mobile-first responsive design. The UI features a clean, focused layout that prioritizes the scanning viewport and the generated code. I also implemented robust error handling for common camera issues, such as NotAllowedError or NotFoundError, providing users with clear, actionable feedback when the application cannot access the required hardware.
Technical Challenges
One of the biggest hurdles was ensuring high-quality scanning on diverse mobile devices. I solved this by implementing ideal and relaxed constraints for the media stream, allowing the app to scale down its requirements for older hardware without sacrificing quality for modern devices. This project significantly deepened my understanding of Web APIs, real-time decoding algorithms, and the intricacies of building hardware-dependent web applications.
Live 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.