From b0f0186466c39acfa31ffb3e24b526371ab26cff Mon Sep 17 00:00:00 2001 From: codemasher Date: Sat, 20 Nov 2021 16:53:02 +0100 Subject: [PATCH] :octocat: +readFromSource() --- src/QRCode.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/QRCode.php b/src/QRCode.php index 5b71f063d..d60dd3ebe 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -12,7 +12,7 @@ namespace chillerlan\QRCode; use chillerlan\QRCode\Common\{ECICharset, MaskPattern, MaskPatternTester, Mode}; use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Kanji, Number, QRData, QRCodeDataException, QRDataModeInterface, QRMatrix}; -use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, GDLuminanceSource, IMagickLuminanceSource}; +use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, GDLuminanceSource, IMagickLuminanceSource, LuminanceSourceInterface}; use chillerlan\QRCode\Output\{QRCodeOutputException, QRFpdf, QRImage, QRImagick, QRMarkup, QROutputInterface, QRString}; use chillerlan\Settings\SettingsContainerInterface; use function class_exists, class_implements, in_array, mb_convert_encoding, mb_detect_encoding; @@ -248,6 +248,15 @@ class QRCode{ $this->dataSegments[] = $segment; } + /** + * Clears the data segments array + */ + public function clearSegments():self{ + $this->dataSegments = []; + + return $this; + } + /** * ISO/IEC 18004:2000 8.3.2 - Numeric Mode */ @@ -316,21 +325,12 @@ class QRCode{ throw new QRCodeException('unable to add ECI segment'); } - /** - * Clears the data segments array - */ - public function clearSegments():self{ - $this->dataSegments = []; - - return $this; - } - /** * Reads a QR Code from a given file */ public function readFromFile(string $path):DecoderResult{ /** @noinspection PhpUndefinedMethodInspection */ - return (new Decoder)->decode($this->luminanceSourceClass::fromFile($path)); + return $this->readFromSource($this->luminanceSourceClass::fromFile($path)); } /** @@ -338,7 +338,15 @@ class QRCode{ */ public function readFromBlob(string $blob):DecoderResult{ /** @noinspection PhpUndefinedMethodInspection */ - return (new Decoder)->decode($this->luminanceSourceClass::fromBlob($blob)); + return $this->readFromSource($this->luminanceSourceClass::fromBlob($blob)); + } + + /** + * Reads a QR Code from the given luminance source + */ + public function readFromSource(LuminanceSourceInterface $source):DecoderResult{ + /** @noinspection PhpUndefinedMethodInspection */ + return (new Decoder)->decode($source); } }