Browse Source

:octocat: support compression quality in QRImagick

smiley 2 năm trước cách đây
mục cha
commit
b434bf54f2
2 tập tin đã thay đổi với 9 bổ sung3 xóa
  1. 4 2
      examples/imagick.php
  2. 5 1
      src/Output/QRImagick.php

+ 4 - 2
examples/imagick.php

@@ -18,11 +18,13 @@ $options = new QROptions;
 
 
 $options->version             = 7;
 $options->version             = 7;
 $options->outputType          = QROutputInterface::IMAGICK;
 $options->outputType          = QROutputInterface::IMAGICK;
+$options->imagickFormat       = 'webp';
+$options->quality             = 90;
 $options->scale               = 20;
 $options->scale               = 20;
 $options->outputBase64        = false;
 $options->outputBase64        = false;
 $options->bgColor             = '#ccccaa';
 $options->bgColor             = '#ccccaa';
 $options->imageTransparent    = true;
 $options->imageTransparent    = true;
-#$options->transparencyColor   = '#ECF9BE';
+$options->transparencyColor   = '#ccccaa';
 $options->drawLightModules    = true;
 $options->drawLightModules    = true;
 $options->drawCircularModules = true;
 $options->drawCircularModules = true;
 $options->circleRadius        = 0.4;
 $options->circleRadius        = 0.4;
@@ -63,7 +65,7 @@ $options->moduleValues        = [
 $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
 $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
 
 
 
 
-header('Content-type: image/png');
+header('Content-type: image/webp');
 
 
 echo $out;
 echo $out;
 
 

+ 5 - 1
src/Output/QRImagick.php

@@ -15,7 +15,7 @@ namespace chillerlan\QRCode\Output;
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\Settings\SettingsContainerInterface;
 use chillerlan\Settings\SettingsContainerInterface;
 use finfo, Imagick, ImagickDraw, ImagickPixel;
 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;
 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);
 		$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();
 		$this->drawImage();
 		// set transparency color after all operations
 		// set transparency color after all operations
 		$this->setTransparencyColor();
 		$this->setTransparencyColor();