added QRGdImageAVIF

This commit is contained in:
smiley
2023-11-27 23:29:54 +01:00
parent 054b76a631
commit d8ccc242d3
5 changed files with 75 additions and 9 deletions
+2 -1
View File
@@ -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;
}
+33
View File
@@ -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
View File
@@ -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,
];
/**
+31
View File
@@ -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
View File
@@ -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(