Skip to content

Commit bca2b42

Browse files
committed
feat(TaskProcessing): Add OCR TaskType
Signed-off-by: Marcel Klehr <[email protected]>
1 parent c0a4098 commit bca2b42

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\TaskProcessing\TaskTypes;
11+
12+
use OCP\IL10N;
13+
use OCP\L10N\IFactory;
14+
use OCP\TaskProcessing\EShapeType;
15+
use OCP\TaskProcessing\ITaskType;
16+
use OCP\TaskProcessing\ShapeDescriptor;
17+
18+
/**
19+
* This is the task processing task type for COR
20+
* @since 33.0.0
21+
*/
22+
class ImageToTextOpticalCharacterRecognition implements ITaskType {
23+
/**
24+
* @since 33.0.0
25+
*/
26+
public const ID = 'core:image2text:ocr';
27+
28+
private IL10N $l;
29+
30+
/**
31+
* @param IFactory $l10nFactory
32+
* @since 33.0.0
33+
*/
34+
public function __construct(
35+
IFactory $l10nFactory,
36+
) {
37+
$this->l = $l10nFactory->get('lib');
38+
}
39+
40+
41+
/**
42+
* @inheritDoc
43+
* @since 33.0.0
44+
*/
45+
public function getName(): string {
46+
return $this->l->t('Optical character recognition');
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
* @since 33.0.0
52+
*/
53+
public function getDescription(): string {
54+
return $this->l->t('Extract text from an image');
55+
}
56+
57+
/**
58+
* @return string
59+
* @since 33.0.0
60+
*/
61+
public function getId(): string {
62+
return self::ID;
63+
}
64+
65+
/**
66+
* @return ShapeDescriptor[]
67+
* @since 33.0.0
68+
*/
69+
public function getInputShape(): array {
70+
return [
71+
'input' => new ShapeDescriptor(
72+
$this->l->t('Input Image'),
73+
$this->l->t('The image to extract text from'),
74+
EShapeType::Image
75+
),
76+
];
77+
}
78+
79+
/**
80+
* @return ShapeDescriptor[]
81+
* @since 33.0.0
82+
*/
83+
public function getOutputShape(): array {
84+
return [
85+
'output' => new ShapeDescriptor(
86+
$this->l->t('Output text'),
87+
$this->l->t('The text that was extracted from the image'),
88+
EShapeType::Text
89+
),
90+
];
91+
}
92+
}

0 commit comments

Comments
 (0)