From d8ccc242d3a49eb6dd076612c5b67308a8cb19ce Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 27 Nov 2023 23:29:54 +0100 Subject: [PATCH] :sparkles: added QRGdImageAVIF --- src/Output/QRGdImage.php | 3 ++- src/Output/QRGdImageAVIF.php | 33 +++++++++++++++++++++++++++ src/Output/QROutputInterface.php | 11 +++++---- tests/Output/QRGdImageAVIFTest.php | 31 +++++++++++++++++++++++++ tests/Output/QROutputTestAbstract.php | 6 ++--- 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 src/Output/QRGdImageAVIF.php create mode 100644 tests/Output/QRGdImageAVIFTest.php diff --git a/src/Output/QRGdImage.php b/src/Output/QRGdImage.php index 4bc886d76..024b071c3 100644 --- a/src/Output/QRGdImage.php +++ b/src/Output/QRGdImage.php @@ -83,6 +83,7 @@ abstract class QRGdImage extends QROutputAbstract{ } $modes = [ + QRGdImageAVIF::class => 'AVIF Support', QRGdImageBMP::class => 'BMP Support', QRGdImageGIF::class => 'GIF Create Support', QRGdImageJPEG::class => 'JPEG Support', @@ -90,7 +91,7 @@ abstract class QRGdImage extends QROutputAbstract{ QRGdImageWEBP::class => 'WebP Support', ]; - // likely using custom output + // likely using custom output/manual invocation if(!isset($modes[$this->options->outputInterface])){ return; } diff --git a/src/Output/QRGdImageAVIF.php b/src/Output/QRGdImageAVIF.php new file mode 100644 index 000000000..1efa6f1c3 --- /dev/null +++ b/src/Output/QRGdImageAVIF.php @@ -0,0 +1,33 @@ + + * @copyright 2023 smiley + * @license MIT + * + * @noinspection PhpComposerExtensionStubsInspection + */ + +namespace chillerlan\QRCode\Output; + +use function imageavif, max, min; + +/** + * GDImage avif output + * + * @see \imageavif() + */ +class QRGdImageAVIF extends QRGdImage{ + + final public const MIME_TYPE = 'image/avif'; + + /** + * @inheritDoc + */ + protected function renderImage():void{ + imageavif($this->image, null, max(-1, min(100, $this->options->quality))); + } + +} diff --git a/src/Output/QROutputInterface.php b/src/Output/QROutputInterface.php index ae0f0211b..94fdbba0e 100644 --- a/src/Output/QROutputInterface.php +++ b/src/Output/QROutputInterface.php @@ -24,18 +24,19 @@ interface QROutputInterface{ * @see https://github.com/chillerlan/php-qrcode/issues/223 */ public const MODES = [ - QRMarkupSVG::class, - QRMarkupHTML::class, + QREps::class, + QRFpdf::class, + QRGdImageAVIF::class, QRGdImageBMP::class, QRGdImageGIF::class, QRGdImageJPEG::class, QRGdImagePNG::class, QRGdImageWEBP::class, + QRImagick::class, + QRMarkupHTML::class, + QRMarkupSVG::class, QRStringJSON::class, QRStringText::class, - QRImagick::class, - QRFpdf::class, - QREps::class, ]; /** diff --git a/tests/Output/QRGdImageAVIFTest.php b/tests/Output/QRGdImageAVIFTest.php new file mode 100644 index 000000000..13dbbf377 --- /dev/null +++ b/tests/Output/QRGdImageAVIFTest.php @@ -0,0 +1,31 @@ + + * @copyright 2023 smiley + * @license MIT + */ + +namespace Output; + +use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCodeTest\Output\QRGdImageTestAbstract; +use chillerlan\QRCode\Output\{QRGdImageAVIF, QROutputInterface}; +use chillerlan\Settings\SettingsContainerInterface; + +/** + * + */ +final class QRGdImageAVIFTest extends QRGdImageTestAbstract{ + + protected function getOutputInterface( + SettingsContainerInterface|QROptions $options, + QRMatrix $matrix + ):QROutputInterface{ + return new QRGdImageAVIF($options, $matrix); + } + +} diff --git a/tests/Output/QROutputTestAbstract.php b/tests/Output/QROutputTestAbstract.php index bf6f0296b..3c9f8e2e4 100644 --- a/tests/Output/QROutputTestAbstract.php +++ b/tests/Output/QROutputTestAbstract.php @@ -40,9 +40,9 @@ abstract class QROutputTestAbstract extends TestCase{ mkdir($this::buildDir, 0777, true); } - $this->options = new QROptions; - $this->matrix = (new QRCode($this->options))->addByteSegment('testdata')->getQRMatrix(); - $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix); + $this->options = new QROptions; + $this->matrix = (new QRCode($this->options))->addByteSegment('testdata')->getQRMatrix(); + $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix); } abstract protected function getOutputInterface(