diff --git a/src/Generator.php b/src/Generator.php index 4ada416..1a412bd 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -143,6 +143,13 @@ class Generator */ protected $imagePercentage = .2; + /** + * The compression quality for PNG image + * + * @var int + */ + protected $compressionQuality = 100; + /** * Creates a new datatype object and then generates a QrCode. * @@ -461,7 +468,7 @@ public function getRendererStyle(): RendererStyle public function getFormatter(): ImageBackEndInterface { if ($this->format === 'png') { - return new ImagickImageBackEnd('png'); + return new ImagickImageBackEnd('png', $this->compressionQuality); } if ($this->format === 'eps') { @@ -544,6 +551,24 @@ public function createColor(int $red, int $green, int $blue, ?int $alpha = null) return new Alpha($alpha, new Rgb($red, $green, $blue)); } + /** + * Sets the compression quality + * + * @param int $quality + * + * @return Generator + */ + public function setPngCompression(int $quality) + { + if ($quality < 1 || $quality > 100) { + throw new InvalidArgumentException("\$quality must be between 1 and 100. {$quality} is not valid."); + } + + $this->compressionQuality = $quality; + + return $this; + } + /** * Creates a new DataType class dynamically. *