From 046016e76ef1e74b97cfd7a3b4dec27a3aa9b4aa Mon Sep 17 00:00:00 2001 From: smiley Date: Fri, 19 Apr 2024 10:03:47 +0200 Subject: [PATCH] :octocat: separate QR reader options --- src/QRCodeReaderOptionsTrait.php | 49 ++++++++++++++++++++++++++++++++ src/QROptions.php | 2 +- src/QROptionsTrait.php | 36 +---------------------- 3 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 src/QRCodeReaderOptionsTrait.php diff --git a/src/QRCodeReaderOptionsTrait.php b/src/QRCodeReaderOptionsTrait.php new file mode 100644 index 000000000..16b7da4be --- /dev/null +++ b/src/QRCodeReaderOptionsTrait.php @@ -0,0 +1,49 @@ + + * @copyright 2024 smiley + * @license MIT + */ + +namespace chillerlan\QRCode; + +use function extension_loaded; + +/** + * Trait QRCodeReaderOptionsTrait + */ +trait QRCodeReaderOptionsTrait{ + + /** + * Use Imagick (if available) when reading QR Codes + */ + protected bool $readerUseImagickIfAvailable = false; + + /** + * Grayscale the image before reading + */ + protected bool $readerGrayscale = false; + + /** + * Invert the colors of the image + */ + protected bool $readerInvertColors = false; + + /** + * Increase the contrast before reading + * + * note that applying contrast works different in GD and Imagick, so mileage may vary + */ + protected bool $readerIncreaseContrast = false; + + /** + * enables Imagick for the QR Code reader if the extension is available + */ + protected function set_readerUseImagickIfAvailable(bool $useImagickIfAvailable):void{ + $this->readerUseImagickIfAvailable = ($useImagickIfAvailable && extension_loaded('imagick')); + } + +} diff --git a/src/QROptions.php b/src/QROptions.php index 91b5b4568..929877d0f 100644 --- a/src/QROptions.php +++ b/src/QROptions.php @@ -16,5 +16,5 @@ use chillerlan\Settings\SettingsContainerAbstract; * The QRCode settings container */ class QROptions extends SettingsContainerAbstract{ - use QROptionsTrait; + use QROptionsTrait, QRCodeReaderOptionsTrait; } diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index 17144143d..86a54b4ac 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -16,7 +16,7 @@ namespace chillerlan\QRCode; use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version}; use chillerlan\QRCode\Output\QRMarkupSVG; -use function constant, extension_loaded, in_array, is_string, max, min, sprintf, strtolower, strtoupper, trim; +use function constant, in_array, is_string, max, min, sprintf, strtolower, strtoupper, trim; use const JSON_THROW_ON_ERROR, PHP_EOL; /** @@ -427,33 +427,6 @@ trait QROptionsTrait{ protected string $fpdfMeasureUnit = 'pt'; - /* - * QR Code reader settings - */ - - /** - * Use Imagick (if available) when reading QR Codes - */ - protected bool $readerUseImagickIfAvailable = false; - - /** - * Grayscale the image before reading - */ - protected bool $readerGrayscale = false; - - /** - * Invert the colors of the image - */ - protected bool $readerInvertColors = false; - - /** - * Increase the contrast before reading - * - * note that applying contrast works different in GD and Imagick, so mileage may vary - */ - protected bool $readerIncreaseContrast = false; - - /** * clamp min/max version number */ @@ -534,13 +507,6 @@ trait QROptionsTrait{ // @todo throw or ignore silently? } - /** - * enables Imagick for the QR Code reader if the extension is available - */ - protected function set_readerUseImagickIfAvailable(bool $useImagickIfAvailable):void{ - $this->readerUseImagickIfAvailable = ($useImagickIfAvailable && extension_loaded('imagick')); - } - /** * clamp the logo space values between 0 and maximum length (177 modules at version 40) */