Skip to content

Commit d8ccc24

Browse files
committed
✨ added QRGdImageAVIF
1 parent 054b76a commit d8ccc24

File tree

5 files changed

+75
-9
lines changed

5 files changed

+75
-9
lines changed

src/Output/QRGdImage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ protected function checkGD():void{
8383
}
8484

8585
$modes = [
86+
QRGdImageAVIF::class => 'AVIF Support',
8687
QRGdImageBMP::class => 'BMP Support',
8788
QRGdImageGIF::class => 'GIF Create Support',
8889
QRGdImageJPEG::class => 'JPEG Support',
8990
QRGdImagePNG::class => 'PNG Support',
9091
QRGdImageWEBP::class => 'WebP Support',
9192
];
9293

93-
// likely using custom output
94+
// likely using custom output/manual invocation
9495
if(!isset($modes[$this->options->outputInterface])){
9596
return;
9697
}

src/Output/QRGdImageAVIF.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Class QRGdImageAVIF
4+
*
5+
* @created 26.11.2023
6+
* @author smiley <[email protected]>
7+
* @copyright 2023 smiley
8+
* @license MIT
9+
*
10+
* @noinspection PhpComposerExtensionStubsInspection
11+
*/
12+
13+
namespace chillerlan\QRCode\Output;
14+
15+
use function imageavif, max, min;
16+
17+
/**
18+
* GDImage avif output
19+
*
20+
* @see \imageavif()
21+
*/
22+
class QRGdImageAVIF extends QRGdImage{
23+
24+
final public const MIME_TYPE = 'image/avif';
25+
26+
/**
27+
* @inheritDoc
28+
*/
29+
protected function renderImage():void{
30+
imageavif($this->image, null, max(-1, min(100, $this->options->quality)));
31+
}
32+
33+
}

src/Output/QROutputInterface.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ interface QROutputInterface{
2424
* @see https://github.com/chillerlan/php-qrcode/issues/223
2525
*/
2626
public const MODES = [
27-
QRMarkupSVG::class,
28-
QRMarkupHTML::class,
27+
QREps::class,
28+
QRFpdf::class,
29+
QRGdImageAVIF::class,
2930
QRGdImageBMP::class,
3031
QRGdImageGIF::class,
3132
QRGdImageJPEG::class,
3233
QRGdImagePNG::class,
3334
QRGdImageWEBP::class,
35+
QRImagick::class,
36+
QRMarkupHTML::class,
37+
QRMarkupSVG::class,
3438
QRStringJSON::class,
3539
QRStringText::class,
36-
QRImagick::class,
37-
QRFpdf::class,
38-
QREps::class,
3940
];
4041

4142
/**

tests/Output/QRGdImageAVIFTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Class QRGdImageAVIFTest
4+
*
5+
* @created 27.11.2023
6+
* @author smiley <[email protected]>
7+
* @copyright 2023 smiley
8+
* @license MIT
9+
*/
10+
11+
namespace Output;
12+
13+
use chillerlan\QRCode\QROptions;
14+
use chillerlan\QRCode\Data\QRMatrix;
15+
use chillerlan\QRCodeTest\Output\QRGdImageTestAbstract;
16+
use chillerlan\QRCode\Output\{QRGdImageAVIF, QROutputInterface};
17+
use chillerlan\Settings\SettingsContainerInterface;
18+
19+
/**
20+
*
21+
*/
22+
final class QRGdImageAVIFTest extends QRGdImageTestAbstract{
23+
24+
protected function getOutputInterface(
25+
SettingsContainerInterface|QROptions $options,
26+
QRMatrix $matrix
27+
):QROutputInterface{
28+
return new QRGdImageAVIF($options, $matrix);
29+
}
30+
31+
}

tests/Output/QROutputTestAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ protected function setUp():void{
4040
mkdir($this::buildDir, 0777, true);
4141
}
4242

43-
$this->options = new QROptions;
44-
$this->matrix = (new QRCode($this->options))->addByteSegment('testdata')->getQRMatrix();
45-
$this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
43+
$this->options = new QROptions;
44+
$this->matrix = (new QRCode($this->options))->addByteSegment('testdata')->getQRMatrix();
45+
$this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
4646
}
4747

4848
abstract protected function getOutputInterface(

0 commit comments

Comments
 (0)