Skip to content

Commit b434bf5

Browse files
committed
:octocat: support compression quality in QRImagick
1 parent 66e797b commit b434bf5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

examples/imagick.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
$options->version = 7;
2020
$options->outputType = QROutputInterface::IMAGICK;
21+
$options->imagickFormat = 'webp';
22+
$options->quality = 90;
2123
$options->scale = 20;
2224
$options->outputBase64 = false;
2325
$options->bgColor = '#ccccaa';
2426
$options->imageTransparent = true;
25-
#$options->transparencyColor = '#ECF9BE';
27+
$options->transparencyColor = '#ccccaa';
2628
$options->drawLightModules = true;
2729
$options->drawCircularModules = true;
2830
$options->circleRadius = 0.4;
@@ -63,7 +65,7 @@
6365
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
6466

6567

66-
header('Content-type: image/png');
68+
header('Content-type: image/webp');
6769

6870
echo $out;
6971

src/Output/QRImagick.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use chillerlan\QRCode\Data\QRMatrix;
1616
use chillerlan\Settings\SettingsContainerInterface;
1717
use finfo, Imagick, ImagickDraw, ImagickPixel;
18-
use function extension_loaded, in_array, is_string, preg_match, strlen;
18+
use function extension_loaded, in_array, is_string, max, min, preg_match, strlen;
1919
use const FILEINFO_MIME_TYPE;
2020

2121
/**
@@ -121,6 +121,10 @@ public function dump(string $file = null){
121121

122122
$this->imagick->newImage($this->length, $this->length, $this->background, $this->options->imagickFormat);
123123

124+
if($this->options->quality > -1){
125+
$this->imagick->setImageCompressionQuality(max(0, min(100, $this->options->quality)));
126+
}
127+
124128
$this->drawImage();
125129
// set transparency color after all operations
126130
$this->setTransparencyColor();

0 commit comments

Comments
 (0)