Skip to content
Advertisement

How to scan a barcode with livestream through webbrowser on on mobile phone in javascript?

I’m trying to make a way to scan irl barcodes that I have printed out on paper to scan into my php website. It’s only when I use the website on my phone, than I can open my phone camera and scan a barcod while he scans the barcode and sends it to my code. The code can than check my database etc.

I found a beautiful plugin to do this called QuaggaJS, I have been playing around with it and at the moment I come further than taking a picture and let it read the barcode and the sends it to my code but I want to let it scan while I hold my camera in front of the barcode so it will close the camera out of himself. Here is an example(on a desktop it would ask permission to open webcam).

In the end I want a button where I click on in my website that opens my camera so I can scan the code and when he finds a barcode he close the camera and show me the information from the product that has this barcode. Is there someone that can help me with it?

Here is some code that I used and played with. (Only works with taking picture)

JavaScript

Best regards

Advertisement

Answer

Took me some time to get it done on myself but I found it out. I also had to get a certificate so my website is secure and allows me to use GetUserMedia(); This is my code that I used now. With $code = $_GET['barcode']; I can take the variable to do other stuff with it, all up to yourself.

php code

JavaScript

Javascript/QuaggaJS

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement