%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php namespace Zxing; use Exception; use Zxing\Common\HybridBinarizer; use Zxing\Qrcode\QRCodeReader; final class QrReader { /** * @var string */ public const SOURCE_TYPE_FILE = 'file'; /** * @var string */ public const SOURCE_TYPE_BLOB = 'blob'; /** * @var string */ public const SOURCE_TYPE_RESOURCE = 'resource'; private readonly \Zxing\BinaryBitmap $bitmap; private readonly \Zxing\Qrcode\QRCodeReader $reader; private \Zxing\Result|bool|null $result = null; private ?Exception $error = 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 $e) { $this->result = false; $this->error = $e; } } 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(): bool|Result|null { return $this->result; } public function getError(): Exception|null { return $this->error; } }