Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/vendor/khanamiryan/qrcode-detector-decoder/lib/ |
<?php namespace Zxing; use Zxing\Common\HybridBinarizer; use Zxing\Qrcode\QRCodeReader; final class QrReader { public const SOURCE_TYPE_FILE = 'file'; public const SOURCE_TYPE_BLOB = 'blob'; public const SOURCE_TYPE_RESOURCE = 'resource'; private readonly \Zxing\BinaryBitmap $bitmap; private readonly \Zxing\Qrcode\QRCodeReader $reader; private \Zxing\Result|bool|null $result = null; 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 (!$im instanceof \GdImage && !is_object($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($hints = null): void { try { $this->result = $this->reader->decode($this->bitmap, $hints); } catch (NotFoundException|FormatException|ChecksumException) { $this->result = false; } } public function text($hints = null) { $this->decode($hints); if ($this->result !== false && method_exists($this->result, 'toString')) { return $this->result->toString(); } return $this->result; } public function getResult() { return $this->result; } }