说明:扩展需要依赖ImageMagick和zbar,安装前先安装这两个软件
yum install ImageMagick.x86_64 ImageMagick-devel.x86_64
tar jxvf zbar-0.10.tar.bz2
cd zbar-0.10
#注意此步有大坑,要禁止gtk,
python和qt的支持,不然你就等着无限报错吧
./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
unzip php-zbarcode-master.zip
cd php-zbarcode-master
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
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/
4.添加:extension=zbarcode.so 到php.ini配置文件
此时查看phpinfo();后搜索zbarcode后为完成
5.测试效果
图片取自https://en.wikipedia.org/wiki/File:Ean-13-5901234123457.png
- <?php
-
- $image = new ZBarCodeImage("./test.png");
-
-
- $scanner = new ZBarCodeScanner();
-
-
- $barcode = $scanner->scan($image);
-
-
- if (!empty($barcode)) {
- foreach ($barcode as $code) {
- printf("Found type %s barcode with data %s\n", $code[‘type‘], $code[‘data‘]);
- }
- }
- ?>