濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容圖文講解

Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容圖文講解

熱門標(biāo)簽:安裝電銷外呼系統(tǒng) 百度商鋪地圖標(biāo)注 釘釘打卡地圖標(biāo)注 地圖標(biāo)注平臺(tái)怎么給錢注冊(cè) 衡水外呼系統(tǒng)平臺(tái) 注冊(cè)400電話申請(qǐng) 新河科技智能外呼系統(tǒng)怎么樣 常州地圖標(biāo)注服務(wù)商 福州人工外呼系統(tǒng)哪家強(qiáng)

一、下載PHP版本的Zxing擴(kuò)展庫(kù)

下載地址:https://github.com/khanamiryan/php-qrcode-detector-decoder

二、使用Zxing擴(kuò)展庫(kù)

1、文件下載好后,直接解壓,結(jié)構(gòu)如下,我們只需要lib這個(gè)文件夾

2、將lib文件夾重命名為Zxing,然后打開Zxing目錄下的QrReader.php文件,可以發(fā)現(xiàn)命名空間是Zxing

3、接下來(lái)就很簡(jiǎn)單了,把Zxing文件夾放到thnikphp的擴(kuò)展目錄extend里

4、報(bào)錯(cuò) Fatal error:: Allowed memory size of 134217728 bytes exhausted (tried to allocate 40 bytes) in

報(bào)錯(cuò)原因:PHP內(nèi)存不夠

解決方法:在調(diào)用QrReader前,先用ini_set()方法修改內(nèi)存限制大小

//修改php內(nèi)存限制為1024M
ini_set('memory_limit','1024M');

5、報(bào)錯(cuò) Call to undefined function Zxing\Common\fill_array()

解決方法:修改Zxing目錄的QrReader.php文件,載入common/customFunctions.php文件,如下:

?php
namespace Zxing;
 
use Zxing\Common\HybridBinarizer;
use Zxing\Qrcode\QRCodeReader;
include_once('common/customFunctions.php');
 
final class QrReader
{
}

QrReader.php完整代碼:

?php
namespace Zxing;
 
use Zxing\Common\HybridBinarizer;
use Zxing\Qrcode\QRCodeReader;
include_once('common/customFunctions.php');
 
final class QrReader
{
 const SOURCE_TYPE_FILE  = 'file';
 const SOURCE_TYPE_BLOB  = 'blob';
 const SOURCE_TYPE_RESOURCE = 'resource';
 
 private $bitmap;
 private $reader;
 private $result;
 
 public function __construct($imgSource, $sourceType = QrReader::SOURCE_TYPE_FILE, $useImagickIfAvailable = true)
 {
  if (!in_array($sourceType, [
   self::SOURCE_TYPE_FILE,
   self::SOURCE_TYPE_BLOB,
   self::SOURCE_TYPE_RESOURCE,
  ], true)) {
   throw new \InvalidArgumentException('Invalid image source.');
  }
  $im = null;
  switch ($sourceType) {
   case QrReader::SOURCE_TYPE_FILE:
    if ($useImagickIfAvailable  extension_loaded('imagick')) {
     $im = new \Imagick();
     $im->readImage($imgSource);
    } else {
     $image = file_get_contents($imgSource);
     $im = imagecreatefromstring($image);
    }
    break;
 
   case QrReader::SOURCE_TYPE_BLOB:
    if ($useImagickIfAvailable  extension_loaded('imagick')) {
     $im = new \Imagick();
     $im->readImageBlob($imgSource);
    } else {
     $im = imagecreatefromstring($imgSource);
    }
    break;
 
   case QrReader::SOURCE_TYPE_RESOURCE:
    $im = $imgSource;
    if ($useImagickIfAvailable  extension_loaded('imagick')) {
     $useImagickIfAvailable = true;
    } else {
     $useImagickIfAvailable = false;
    }
    break;
  }
  if ($useImagickIfAvailable  extension_loaded('imagick')) {
   if (!$im instanceof \Imagick) {
    throw new \InvalidArgumentException('Invalid image source.');
   }
   $width = $im->getImageWidth();
   $height = $im->getImageHeight();
   $source = new IMagickLuminanceSource($im, $width, $height);
  } else {
   if (!is_resource($im)) {
    throw new \InvalidArgumentException('Invalid image source.');
   }
   $width = imagesx($im);
   $height = imagesy($im);
   $source = new GDLuminanceSource($im, $width, $height);
  }
  $histo  = new HybridBinarizer($source);
  $this->bitmap = new BinaryBitmap($histo);
  $this->reader = new QRCodeReader();
 }
 
 public function decode()
 {
  try {
   $this->result = $this->reader->decode($this->bitmap);
  } catch (NotFoundException $er) {
   $this->result = false;
  } catch (FormatException $er) {
   $this->result = false;
  } catch (ChecksumException $er) {
   $this->result = false;
  }
 }
 
 public function text()
 {
  $this->decode();
 
  if (method_exists($this->result, 'toString')) {
   return $this->result->toString();
  }
 
  return $this->result;
 }
 
 public function getResult()
 {
  return $this->result;
 }
}

6、在代碼里調(diào)用

//引用
use Zxing\QrReader;
//調(diào)用類庫(kù)
$qrcode = new QrReader("二維碼圖片路徑"); 
$content = $qrcode->text();

到此這篇關(guān)于Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容圖文講解的文章就介紹到這了,更多相關(guān)Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • php+laravel 掃碼二維碼簽到功能
  • PHP實(shí)現(xiàn)一個(gè)二維碼同時(shí)支持支付寶和微信支付的示例
  • PHP基于phpqrcode類生成二維碼的方法示例詳解
  • PHP基于phpqrcode類庫(kù)生成二維碼過(guò)程解析
  • thinkphp3.2框架集成QRcode生成二維碼的方法分析
  • PHP生成二維碼與識(shí)別二維碼的方法詳解【附源碼下載】
  • php生成二維碼不保存服務(wù)器還有下載功能的實(shí)現(xiàn)代碼
  • PHP二維碼的生成與識(shí)別案例

標(biāo)簽:白城 六安 鶴崗 柳州 唐山 鷹潭 克拉瑪依 遼陽(yáng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容圖文講解》,本文關(guān)鍵詞  Thinkphp,使用,Zxing,擴(kuò)展,庫(kù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容圖文講解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Thinkphp使用Zxing擴(kuò)展庫(kù)解析二維碼內(nèi)容圖文講解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    高密市| 喜德县| 调兵山市| 阳谷县| 巴楚县| 额济纳旗| 沁水县| 黄浦区| 温宿县| 织金县| 龙川县| 花垣县| 镇赉县| 沙洋县| 万全县| 夹江县| 翁牛特旗| 贵州省| 锡林郭勒盟| 康保县| 施秉县| 澄城县| 佳木斯市| 监利县| 麟游县| 嘉峪关市| 古浪县| 仁寿县| 平昌县| 沽源县| 宿松县| 溧阳市| 木里| 尼玛县| 安乡县| 西乌珠穆沁旗| 沁水县| 青神县| 乌海市| 济源市| 开阳县|