Просмотр исходного кода

:sparkles: added QRGdImageAVIF

smiley 2 лет назад
Родитель
Сommit
d8ccc242d3

+ 2 - 1
src/Output/QRGdImage.php

@@ -83,6 +83,7 @@ abstract class QRGdImage extends QROutputAbstract{
 		}
 		}
 
 
 		$modes = [
 		$modes = [
+			QRGdImageAVIF::class => 'AVIF Support',
 			QRGdImageBMP::class  => 'BMP Support',
 			QRGdImageBMP::class  => 'BMP Support',
 			QRGdImageGIF::class  => 'GIF Create Support',
 			QRGdImageGIF::class  => 'GIF Create Support',
 			QRGdImageJPEG::class => 'JPEG Support',
 			QRGdImageJPEG::class => 'JPEG Support',
@@ -90,7 +91,7 @@ abstract class QRGdImage extends QROutputAbstract{
 			QRGdImageWEBP::class => 'WebP Support',
 			QRGdImageWEBP::class => 'WebP Support',
 		];
 		];
 
 
-		// likely using custom output
+		// likely using custom output/manual invocation
 		if(!isset($modes[$this->options->outputInterface])){
 		if(!isset($modes[$this->options->outputInterface])){
 			return;
 			return;
 		}
 		}

+ 33 - 0
src/Output/QRGdImageAVIF.php

@@ -0,0 +1,33 @@
+<?php
+/**
+ * Class QRGdImageAVIF
+ *
+ * @created      26.11.2023
+ * @author       smiley <smiley@chillerlan.net>
+ * @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)));
+	}
+
+}

+ 6 - 5
src/Output/QROutputInterface.php

@@ -24,18 +24,19 @@ interface QROutputInterface{
 	 * @see https://github.com/chillerlan/php-qrcode/issues/223
 	 * @see https://github.com/chillerlan/php-qrcode/issues/223
 	 */
 	 */
 	public const MODES = [
 	public const MODES = [
-		QRMarkupSVG::class,
-		QRMarkupHTML::class,
+		QREps::class,
+		QRFpdf::class,
+		QRGdImageAVIF::class,
 		QRGdImageBMP::class,
 		QRGdImageBMP::class,
 		QRGdImageGIF::class,
 		QRGdImageGIF::class,
 		QRGdImageJPEG::class,
 		QRGdImageJPEG::class,
 		QRGdImagePNG::class,
 		QRGdImagePNG::class,
 		QRGdImageWEBP::class,
 		QRGdImageWEBP::class,
+		QRImagick::class,
+		QRMarkupHTML::class,
+		QRMarkupSVG::class,
 		QRStringJSON::class,
 		QRStringJSON::class,
 		QRStringText::class,
 		QRStringText::class,
-		QRImagick::class,
-		QRFpdf::class,
-		QREps::class,
 	];
 	];
 
 
 	/**
 	/**

+ 31 - 0
tests/Output/QRGdImageAVIFTest.php

@@ -0,0 +1,31 @@
+<?php
+/**
+ * Class QRGdImageAVIFTest
+ *
+ * @created      27.11.2023
+ * @author       smiley <smiley@chillerlan.net>
+ * @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);
+	}
+
+}

+ 3 - 3
tests/Output/QROutputTestAbstract.php

@@ -40,9 +40,9 @@ abstract class QROutputTestAbstract extends TestCase{
 			mkdir($this::buildDir, 0777, true);
 			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(
 	abstract protected function getOutputInterface(