Read/decode bar codes from an image in php

大兔子大兔子 提交于 2019-12-05 05:35:44

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!

Another Person

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