I am look at building a 13 digit EAN bar code scanner which works on the web on mobile devices and will use the devices camera to take an image of bar code to scan and decode. I'm not trying to do this through a native app as I would prefer to make this part of my native website search experience. E.g. website visitors on a mobile will be prompted to scan a bar code without having to open an app.
This script works well on desktop https://github.com/EddieLa/JOB and uses the Navigator.getUserMedia property to do all this in JavaScript however support in Android is only just starting and support on IOS is non-existent http://caniuse.com/#feat=stream
So I am wondering if I can instead, to support mobile devices which is the whole point of what I am trying to do, rather than read the bar code in the browser, take a picture of the bar code, send this to a server via Ajax, have the server decode the image and send the response back to webpage.
With this approach I know there are python scripts which can read a bar code, such as https://pypi.python.org/pypi/zbar, however are there PHP equivalents to this?
From my experience ZBAR is just the best one I found after a long research and many tries with other free options available, including BarBara. Just download and install ZBar (depending on your OS) and run PHP's exec
command. Windows example:
exec('C:\\"Program Files (x86)"\\ZBar\\bin\\zbarimg -q C:\\path\\img.jpg', $result);
print_r($result);
I run ZBar in 10.000+ big images in many formats (jpg, gif, png & bmp) and it detected the barcodes successfully in about 70% of them. It can read many barcode formats, including EAN-13, QR-Code and others, and can read multiple barcodes in the same image as well. Defenitely worth a try!
Use BarBara Bar Code Library:
official site: http://sourceforge.net/projects/barbara
download php source code: http://sourceforge.net/projects/barbara/files/BarBara%20Source/PHP5/barbara.zip/download
Testing:
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once "barcode.php";
$bc = new barcode;
$scanner = new BarScan;
$bc->load("barcode.js");
echo "Dictionary Loaded..";
$scanner->Codecs = $bc;
echo "Test";
//Manually set code type
$scanner->CodeType = $bc->code39;
$img = new Imagick("test/code-25.gif");
echo "Image Loaded...";
echo "<br />Decoded: " . $scanner->Scan($img, 0, 20, 2048, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With