Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to change PNG compression quality #288

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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