Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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.
*
Expand Down