Skip to content

Commit e59d72f

Browse files
committed
Merge branch 'master' of https://github.com/Lea-Reift/ocr-space
2 parents 928ba01 + 2704355 commit e59d72f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ public function isTable(bool $isTable): self
233233

234234
public function engine(int $engine = 1): self
235235
{
236+
if ($engine === 2 && !$this->requestParameters->contains(RequestParameterEnum::LANGUAGE)) {
237+
$this->requestParameters->attach(RequestParameterEnum::LANGUAGE, "auto");
238+
}
236239
$this->requestParameters->attach(RequestParameterEnum::OCR_ENGINE, $engine);
237240
return $this;
238241
}

tests/Feature/ClientTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,31 @@ public function testOptionsReturnsCorrectParameters(): void
286286
$this->assertArrayHasKey('OCREngine', $options);
287287
$this->assertSame(2, $options['OCREngine']);
288288
}
289+
290+
public function testSetLanguageAutoIfEngineIs2()
291+
{
292+
$this->client
293+
->fromUrl("https://example.com/image.png")
294+
->isOverlayRequired(true)
295+
->fileType(FileTypeEnum::PDF)
296+
->engine(2);
297+
298+
$options = $this->client->options();
299+
$this->assertArrayHasKey('language', $options);
300+
$this->assertSame('auto', $options['language']);
301+
}
302+
303+
public function testNotSetLanguageAutoIfEngineIs2AndLangWasSet()
304+
{
305+
$this->client
306+
->fromUrl("https://example.com/image.png")
307+
->language(LanguageCodeEnum::ENGLISH)
308+
->isOverlayRequired(true)
309+
->fileType(FileTypeEnum::PDF)
310+
->engine(2);
311+
312+
$options = $this->client->options();
313+
$this->assertArrayHasKey('language', $options);
314+
$this->assertSame('eng', $options['language']);
315+
}
289316
}

0 commit comments

Comments
 (0)