《LINUX安装PHP-zbarcode插件》要点:
本文介绍了LINUX安装PHP-zbarcode插件,希望对您有用。如果有疑问,可以联系我们。
PHP-zbarcode是php识别二维码的扩展。安装前要先安装ImageMagick、zbar.
https://github.com/mkoppanen/php-zbarcode
官网:
ZBar http://zbar.sourceforge.net/
ImageMagick http://www.imagemagick.org/
有关ImageMagick安装方法另外详解。
下面是ZBar和PHP-zbarcode扩展安装办法:
1、第一步:安装Zbar(截止2017-08-24为止,版本zbar-0.10):
cd /usr/local/src/ 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 #注意此步要禁止gtk,python和qt的支持,如下--without-gtk等等,不然你就等着无限报错吧 ./configure --without-gtk --without-python --without-qt --prefix=/usr/local/zbar make && make install
#提示如下为完成,不是报错
#make[2]: Leaving directory `/root/zbar-0.10'
#make[1]: Leaving directory `/root/zbar-0.10'
echo "/usr/local/zbar/lib/" >> /etc/ld.so.conf ldconfig ln -s /usr/local/zbar/lib/pkgconfig/zbar.pc /usr/lib64/pkgconfig/zbar.pc
2、第二步:安装插件:
wget https://github.com/lgchgt/php-zbarcode/archive/master.zip unzip master.zip (注:有可能跳转到master.zip,看提示,如果是,则执行unzip master.zip) cd php-zbarcode-master /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --with-zbarcode-imagemagick-dir=/usr/local/ImageMagick/ --with-zbarcode=/usr/local/zbar make && make install
#提示如下完成
#Build complete.
#Don't forget to run 'make test'.
#Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
添加:extension=zbarcode.so 到php.ini配置文件
echo "extension=zbarcode.so" >> /usr/local/php/php.d/zbarcode.ini
运行: php -i|grep zbar 检查是否安装功能,或查看phpinfo();搜索zbarcode,如有则安装完成。
3、第三步:PHP测试:
<?php /* Create new image object */ $image = new ZBarCodeImage(“1.jpg”); $scanner = new ZBarCodeScanner(); $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’]); } } ?>
官网教程:
<?php /* Create new image object */ $image = new ZBarCodeImage("test.jpg"); /* Create a barcode scanner */ $scanner = new ZBarCodeScanner(); /* Scan the image */ $barcode = $scanner->scan($image); /* Loop through possible barcodes */ if (!empty($barcode)) { foreach ($barcode as $code) { printf("Found type %s barcode with data %s\n", $code['type'], $code['data']); } } ?>
转载请注明本页网址:
http://www.vephp.com/jiaocheng/167.html