From d9f68476889b4c3e467aede31d16a13a9d0fcafd Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Sat, 5 Mar 2022 23:50:40 +0100 Subject: [PATCH] Add quality option --- src/OptionSet.php | 13 +++++++++++++ test/OptionSetTest.php | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/OptionSet.php b/src/OptionSet.php index eedd8d6..1cc5fa9 100644 --- a/src/OptionSet.php +++ b/src/OptionSet.php @@ -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); diff --git a/test/OptionSetTest.php b/test/OptionSetTest.php index e3f8b2e..98e3c32 100644 --- a/test/OptionSetTest.php +++ b/test/OptionSetTest.php @@ -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();