|
|
@@ -12,6 +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\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;
|
|
|
@@ -80,6 +81,18 @@ class QRCode{
|
|
|
],
|
|
|
];
|
|
|
|
|
|
+ /**
|
|
|
+ * The settings container
|
|
|
+ *
|
|
|
+ * @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface
|
|
|
+ */
|
|
|
+ protected SettingsContainerInterface $options;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The selected data interface (Number, AlphaNum, Kanji, Byte)
|
|
|
+ */
|
|
|
+ protected QRData $dataInterface;
|
|
|
+
|
|
|
/**
|
|
|
* A collection of one or more data segments of [classname, data] to write
|
|
|
*
|
|
|
@@ -90,16 +103,11 @@ class QRCode{
|
|
|
protected array $dataSegments = [];
|
|
|
|
|
|
/**
|
|
|
- * The settings container
|
|
|
+ * The FQCN of the luminance sporce class to use in the reader (GD or Imagick)
|
|
|
*
|
|
|
- * @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface
|
|
|
- */
|
|
|
- protected SettingsContainerInterface $options;
|
|
|
-
|
|
|
- /**
|
|
|
- * The selected data interface (Number, AlphaNum, Kanji, Byte)
|
|
|
+ * @see \chillerlan\QRCode\Decoder\LuminanceSourceInterface
|
|
|
*/
|
|
|
- protected QRData $dataInterface;
|
|
|
+ private string $luminanceSourceClass;
|
|
|
|
|
|
/**
|
|
|
* QRCode constructor.
|
|
|
@@ -107,7 +115,10 @@ class QRCode{
|
|
|
* Sets the options instance
|
|
|
*/
|
|
|
public function __construct(SettingsContainerInterface $options = null){
|
|
|
- $this->options = $options ?? new QROptions;
|
|
|
+ $this->options = $options ?? new QROptions;
|
|
|
+ $this->luminanceSourceClass = $this->options->useImagickIfAvailable
|
|
|
+ ? IMagickLuminanceSource::class
|
|
|
+ : GDLuminanceSource::class;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -305,4 +316,29 @@ 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));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Reads a QR Code from the given data blob
|
|
|
+ */
|
|
|
+ public function readFromBlob(string $blob):DecoderResult{
|
|
|
+ /** @noinspection PhpUndefinedMethodInspection */
|
|
|
+ return (new Decoder)->decode($this->luminanceSourceClass::fromBlob($blob));
|
|
|
+ }
|
|
|
+
|
|
|
}
|