PHP识别二维码功能,php-zbarcode 安装

写之前先鄙视下利用此开源程序收费的人。

php-zbarcode是PHP识别二维码的扩展。

下面是安装方法,安装前要先安装ImageMagick、zbar.

php-zbarcode 下载地址

安装ImageMagick:
yum install ImageMagick.x86_64 ImageMagick-devel.x86_64

安装zbar:
wget http://jaist.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2
tar jxvf zbar-0.10.tar.bz2
cd zbar-0.10
./configure –without-gtk –without-qt –without-python –prefix=/usr/local/zbar
make all
make install
echo “/usr/local/zbar/lib/” >> /etc/ld.so.conf
ldconfig
ln -s /usr/local/zbar/lib/pkgconfig/zbar.pc? /usr/lib64/pkgconfig/zbar.pc

安装php-zbarcode:
wget https://github.com/lgchgt/php-zbarcode/archive/master.zip
unzip master
cd php-zbarcode-master
/xxx/server/php/bin/phpze
/configure –with-php-config=/xxx/server/php/bin/php-config
make
make install

查看是否有:zbarcode.so
ll /xxx/server/php/lib/php/extensions/no-debug-non-zts-20100525/
添加:extension=zbarcode.so 到php.ini配置文件

重启PHP:

service php-fpm restart
运行 : php -i|grep zbar
检查是否安装功能

创建文件:zbar.php
<?php
/* Create new image object */
$image = new ZBarCodeImage(“1.jpg”);

/* Create a barcode scanner */
$scanner = new ZBarCodeScanner();

/* Scan the image */
$barcode = $scanner->scan($image);
print_r($barcode);
/* Loop through possible barcodes */
if (!empty($barcode)) {
foreach ($barcode as $code) {
printf(“Found type %s barcode with data %s\n”, $code[‘type’], $code[‘data’]);
}
}
?>
验证结果;