Skip to content

Commit

Permalink
Merge pull request #10 from christophlehmann/add-quality-option
Browse files Browse the repository at this point in the history
Add quality option
  • Loading branch information
crocodile2u committed Apr 19, 2022
2 parents 4f4eb51 + d9f6847 commit 6575855
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/OptionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,19 @@ public function format(): string
return $this->firstValue(ProcessingOption::FORMAT, 'string');
}

public function withQuality(int $quality): self
{
if ($quality < 0 || $quality > 100) {
throw new \InvalidArgumentException("quality must be >= 0 and <= 100");
}
return $this->set(ProcessingOption::QUALITY, $quality);
}

public function quality(): ?int
{
return $this->firstValue(ProcessingOption::QUALITY, 'int');
}

protected function firstValue(string $name, string $type)
{
$o = $this->get($name);
Expand Down
7 changes: 7 additions & 0 deletions test/OptionSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,13 @@ public function testWithFormat()
$this->assertEquals("webp", $os->format());
}

public function testWithQuality()
{
$os = new OptionSet();
$os->withQuality(70);
$this->assertEquals(70, $os->quality());
}

public function testUnset()
{
$os = new OptionSet();
Expand Down

0 comments on commit 6575855

Please sign in to comment.