:octocat: support compression quality in QRImagick

This commit is contained in:
smiley
2023-09-05 20:51:27 +02:00
parent 66e797b5d8
commit b434bf54f2
2 changed files with 9 additions and 3 deletions
+4 -2
View File
@@ -18,11 +18,13 @@ $options = new QROptions;
$options->version = 7;
$options->outputType = QROutputInterface::IMAGICK;
$options->imagickFormat = 'webp';
$options->quality = 90;
$options->scale = 20;
$options->outputBase64 = false;
$options->bgColor = '#ccccaa';
$options->imageTransparent = true;
#$options->transparencyColor = '#ECF9BE';
$options->transparencyColor = '#ccccaa';
$options->drawLightModules = true;
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
@@ -63,7 +65,7 @@ $options->moduleValues = [
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
header('Content-type: image/png');
header('Content-type: image/webp');
echo $out;
+5 -1
View File
@@ -15,7 +15,7 @@ namespace chillerlan\QRCode\Output;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\Settings\SettingsContainerInterface;
use finfo, Imagick, ImagickDraw, ImagickPixel;
use function extension_loaded, in_array, is_string, preg_match, strlen;
use function extension_loaded, in_array, is_string, max, min, preg_match, strlen;
use const FILEINFO_MIME_TYPE;
/**
@@ -121,6 +121,10 @@ class QRImagick extends QROutputAbstract{
$this->imagick->newImage($this->length, $this->length, $this->background, $this->options->imagickFormat);
if($this->options->quality > -1){
$this->imagick->setImageCompressionQuality(max(0, min(100, $this->options->quality)));
}
$this->drawImage();
// set transparency color after all operations
$this->setTransparencyColor();