Read/decode bar codes from an image in php

青春壹個敷衍的年華 提交于 2019-12-22 04:57:22

问题


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?


回答1:


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!




回答2:


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);


来源:https://stackoverflow.com/questions/31443370/read-decode-bar-codes-from-an-image-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!