From 47ebb6b8f5d3b2fac4657cda6e46004ddb94e404 Mon Sep 17 00:00:00 2001 From: enjoys Date: Sun, 27 Apr 2025 23:25:32 +0300 Subject: [PATCH 1/2] If OCREngine=2 and language not set, send language code `auto`. --- src/Client.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Client.php b/src/Client.php index c4984de..df56f1b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -233,6 +233,9 @@ public function isTable(bool $isTable): self public function engine(int $engine = 1): self { + if ($engine === 2 && !$this->requestParameters->contains(RequestParameterEnum::LANGUAGE)) { + $this->requestParameters->attach(RequestParameterEnum::LANGUAGE, "auto"); + } $this->requestParameters->attach(RequestParameterEnum::OCR_ENGINE, $engine); return $this; } From 17160de172f3df8647762ad4ea707e8940e577b4 Mon Sep 17 00:00:00 2001 From: enjoys Date: Sun, 27 Apr 2025 23:30:23 +0300 Subject: [PATCH 2/2] added tests --- tests/Feature/ClientTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 89d0d34..01f1d0d 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -286,4 +286,31 @@ public function testOptionsReturnsCorrectParameters(): void $this->assertArrayHasKey('OCREngine', $options); $this->assertSame(2, $options['OCREngine']); } + + public function testSetLanguageAutoIfEngineIs2() + { + $this->client + ->fromUrl("https://example.com/image.png") + ->isOverlayRequired(true) + ->fileType(FileTypeEnum::PDF) + ->engine(2); + + $options = $this->client->options(); + $this->assertArrayHasKey('language', $options); + $this->assertSame('auto', $options['language']); + } + + public function testNotSetLanguageAutoIfEngineIs2AndLangWasSet() + { + $this->client + ->fromUrl("https://example.com/image.png") + ->language(LanguageCodeEnum::ENGLISH) + ->isOverlayRequired(true) + ->fileType(FileTypeEnum::PDF) + ->engine(2); + + $options = $this->client->options(); + $this->assertArrayHasKey('language', $options); + $this->assertSame('eng', $options['language']); + } }