Skip to content

Commit

Permalink
Add properties qualityJpg, qualityPng, filtersPng. Add getters and se…
Browse files Browse the repository at this point in the history
…tters from new property
  • Loading branch information
uginroot committed Jul 26, 2019
1 parent 38a213c commit 1ccd56e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
6 changes: 4 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 75 additions & 6 deletions src/ImageResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ class ImageResize
*/
private $height;

/**
* @var int
*/
private $qualityJpeg = -1;

/**
* @var int
*/
private $qualityPng = -1;

/**
* @var int
*/
private $filtersPng = -1;

/**
* @param string $content
* @return static
Expand Down Expand Up @@ -113,10 +128,10 @@ public function save(string $path, int $format = self::FORMAT_JPEG, $overwrite =
}
switch ($format) {
case static::FORMAT_JPEG:
imagejpeg($this->image, $path);
imagejpeg($this->image, $path, $this->qualityJpeg);
break;
case static::FORMAT_PNG:
imagepng($this->image, $path);
imagepng($this->image, $path, $this->qualityPng, $this->filtersPng);
break;
case static::FORMAT_WEBP:
imagewbmp($this->image, $path);
Expand Down Expand Up @@ -162,10 +177,10 @@ public function getContent(int $format = self::FORMAT_JPEG)
$stream = fopen("php://memory", "w+");
switch ($format) {
case static::FORMAT_JPEG:
imagejpeg($this->image, $stream);
imagejpeg($this->image, $stream, $this->qualityJpeg);
break;
case static::FORMAT_PNG:
imagepng($this->image, $stream);
imagepng($this->image, $stream, $this->filtersPng, $this->filtersPng);
break;
case static::FORMAT_WEBP:
imagewbmp($this->image, $stream);
Expand All @@ -189,10 +204,10 @@ public function print(int $format = self::FORMAT_JPEG):void
{
switch ($format) {
case static::FORMAT_JPEG:
imagejpeg($this->image);
imagejpeg($this->image, null, $this->qualityJpeg);
break;
case static::FORMAT_PNG:
imagepng($this->image);
imagepng($this->image, null, $this->filtersPng, $this->filtersPng);
break;
case static::FORMAT_WEBP:
imagewbmp($this->image);
Expand Down Expand Up @@ -906,4 +921,58 @@ public function setWatermark(ImageResize $watermark, int $position = self::POSIT

return $this;
}

/**
* @return int
*/
public function getQualityJpeg(): int
{
return $this->qualityJpeg;
}

/**
* @param int $qualityJpeg
* @return static
*/
public function setQualityJpeg(int $qualityJpeg)
{
$this->qualityJpeg = $qualityJpeg;
return $this;
}

/**
* @return int
*/
public function getQualityPng(): int
{
return $this->qualityPng;
}

/**
* @param int $qualityPng
* @return static
*/
public function setQualityPng(int $qualityPng)
{
$this->qualityPng = $qualityPng;
return $this;
}

/**
* @return int
*/
public function getFiltersPng(): int
{
return $this->filtersPng;
}

/**
* @param int $filtersPng
* @return static
*/
public function setFiltersPng(int $filtersPng)
{
$this->filtersPng = $filtersPng;
return $this;
}
}

0 comments on commit 1ccd56e

Please sign in to comment.