源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP识别二维码的方法(php-zbarcode安装与使用)

  • 时间:2021-11-25 12:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP识别二维码的方法(php-zbarcode安装与使用)
本文实例讲述了PHP识别二维码的方法。分享给大家供大家参考,具体如下: 说明:扩展需要依赖ImageMagick和zbar,安装前先安装这两个软件 1.安装ImageMagick([url=http://www.imagemagick.org/]http://www.imagemagick.org/[/url])
yum install ImageMagick.x86_64 ImageMagick-devel.x86_64

2.安装zbar([url=http://sourceforge.net/projects/zbar/?source=directory]http://sourceforge.net/projects/zbar/?source=directory[/url])
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的支持,不然你就等着无限报错吧
./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

3.安装php-zbarcode([url=https://github.com/mkoppanen/php-zbarcode]https://github.com/mkoppanen/php-zbarcode[/url])
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 另外,用户还可以使用本站二维码生成工具来生成二维码图片进行测试: [url=http://tools.jb51.net/transcoding/jb51qrcode][b]http://tools.jb51.net/transcoding/jb51qrcode[/b][/url] 测试代码如下:
<?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']);
    }
  }
?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/455.htm]PHP图形与图片操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/150.htm]php排序算法总结[/url]》、《[url=http://www.1sucai.cn/Special/242.htm]PHP常用遍历算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/614.htm]PHP数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/111.htm]php程序设计算法总结[/url]》、《[url=http://www.1sucai.cn/Special/630.htm]PHP数学运算技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/180.htm]php正则表达式用法总结[/url]》、《[url=http://www.1sucai.cn/Special/357.htm]PHP运算与运算符用法总结[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部