mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-01 04:58:26 +00:00
:octocat: move luminance source selection back to QRCode
This commit is contained in:
+17
-3
@@ -12,7 +12,7 @@ namespace chillerlan\QRCode;
|
||||
|
||||
use chillerlan\QRCode\Common\{EccLevel, ECICharset, MaskPattern, Mode, Version};
|
||||
use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Kanji, Number, QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
|
||||
use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, LuminanceSourceInterface};
|
||||
use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, GDLuminanceSource, IMagickLuminanceSource, LuminanceSourceInterface};
|
||||
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
use function class_exists, class_implements, in_array, mb_convert_encoding, mb_detect_encoding;
|
||||
@@ -170,6 +170,11 @@ class QRCode{
|
||||
*/
|
||||
protected array $dataSegments = [];
|
||||
|
||||
/**
|
||||
* The luminance source for the reader
|
||||
*/
|
||||
protected string $luminanceSourceFQN = GDLuminanceSource::class;
|
||||
|
||||
/**
|
||||
* QRCode constructor.
|
||||
*
|
||||
@@ -177,6 +182,11 @@ class QRCode{
|
||||
*/
|
||||
public function __construct(SettingsContainerInterface $options = null){
|
||||
$this->options = $options ?? new QROptions;
|
||||
|
||||
// i hate this less
|
||||
if($this->options->readerUseImagickIfAvailable){
|
||||
$this->luminanceSourceFQN = IMagickLuminanceSource::class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,16 +430,20 @@ class QRCode{
|
||||
|
||||
/**
|
||||
* Reads a QR Code from a given file
|
||||
*
|
||||
* @noinspection PhpUndefinedMethodInspection
|
||||
*/
|
||||
public function readFromFile(string $path):DecoderResult{
|
||||
return $this->readFromSource($this->options->getLuminanceSourceFQCN()::fromFile($path, $this->options));
|
||||
return $this->readFromSource($this->luminanceSourceFQN::fromFile($path, $this->options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a QR Code from the given data blob
|
||||
*
|
||||
* @noinspection PhpUndefinedMethodInspection
|
||||
*/
|
||||
public function readFromBlob(string $blob):DecoderResult{
|
||||
return $this->readFromSource($this->options->getLuminanceSourceFQCN()::fromBlob($blob, $this->options));
|
||||
return $this->readFromSource($this->luminanceSourceFQN::fromBlob($blob, $this->options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace chillerlan\QRCode;
|
||||
|
||||
use chillerlan\QRCode\Output\QROutputInterface;
|
||||
use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
|
||||
use chillerlan\QRCode\Decoder\{GDLuminanceSource, IMagickLuminanceSource};
|
||||
use function array_values, count, extension_loaded, in_array, is_numeric, max, min, sprintf, strtolower;
|
||||
|
||||
/**
|
||||
@@ -460,18 +459,6 @@ trait QROptionsTrait{
|
||||
$this->readerUseImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the FQCN of the luminance source class to use in the reader (GD or Imagick)
|
||||
*
|
||||
* @see \chillerlan\QRCode\Decoder\LuminanceSourceInterface
|
||||
*/
|
||||
public function getLuminanceSourceFQCN():string{
|
||||
// i still hate this
|
||||
return $this->readerUseImagickIfAvailable
|
||||
? IMagickLuminanceSource::class
|
||||
: GDLuminanceSource::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* clamp the logo space values between 0 and maximum length (177 modules at version 40)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user