99use ImagickException ;
1010use Mindee \Dependency \DependencyChecker ;
1111use Mindee \Error \ErrorCode ;
12- use Mindee \Error \MindeeGeometryException ;
1312use Mindee \Error \MindeeImageException ;
1413use Mindee \Error \MindeePdfException ;
1514use Mindee \Geometry \BBox ;
1615use Mindee \Geometry \BBoxUtils ;
1716use Mindee \Geometry \Point ;
1817use Mindee \Geometry \Polygon ;
1918use Mindee \Input \LocalInputSource ;
20- use Mindee \V1 \Parsing \Standard \BaseField ;
2119
2220use function count ;
2321use function sprintf ;
@@ -128,20 +126,6 @@ public function getPageCount(): int
128126 return count ($ this ->pageImages );
129127 }
130128
131- /**
132- * Extract multiple images on a given page from a list of fields having position data.
133- *
134- * @param array<BaseField<string|float|integer|boolean|Polygon>> $fields List of Fields to extract.
135- * @param integer $pageIndex The page index to extract, begins at 0.
136- * @param null|string $outputName The base output filename, must have an image extension.
137- *
138- * @return array<ExtractedImage> a list of extracted images
139- */
140- public function extractImagesFromPage (array $ fields , int $ pageIndex , ?string $ outputName = null ): array
141- {
142- $ outputName ??= $ this ->filename ;
143- return $ this ->extractFromPage ($ fields , $ pageIndex , $ outputName );
144- }
145129
146130 /**
147131 * Extracts images from a page.
@@ -212,47 +196,6 @@ public function extractPolygonFromPage(
212196 return new ExtractedImage ($ extractedImageData , $ filename , $ format , $ pageIndex , $ index );
213197 }
214198
215- /**
216- * Extracts a single image from a Position field.
217- *
218- * @param BaseField<string|float|integer|boolean|Polygon> $field The field to extract.
219- * @param integer $pageIndex The page index to extract, begins at 0.
220- * @param integer $index The index to use for naming the extracted image.
221- * @param string $filename The output filename.
222- * @param string $format The output format.
223- *
224- * @return null|ExtractedImage The extracted image, or null if the field does not have valid position data.
225- *
226- * @throws MindeeGeometryException Throws if a field does not contain positional data.
227- */
228- public function extractImage (
229- BaseField $ field ,
230- int $ pageIndex ,
231- int $ index ,
232- string $ filename ,
233- string $ format
234- ): ?ExtractedImage {
235- $ polygon = null ;
236-
237- if (!empty ($ field ->polygon )) {
238- $ polygon = $ field ->polygon ;
239- } elseif (!empty ($ field ->boundingBox )) {
240- $ polygon = $ field ->boundingBox ;
241- } elseif (!empty ($ field ->quadrangle )) {
242- $ polygon = $ field ->quadrangle ;
243- } elseif (!empty ($ field ->rectangle )) {
244- $ polygon = $ field ->rectangle ;
245- }
246-
247- if (null === $ polygon ) {
248- throw new MindeeGeometryException (
249- 'Provided field has no valid position data. ' ,
250- ErrorCode::GEOMETRIC_OPERATION_FAILED
251- );
252- }
253-
254- return $ this ->extractPolygonFromPage ($ polygon , $ pageIndex , $ index , $ filename , $ format );
255- }
256199
257200 /**
258201 * Getter for the local input source.
@@ -262,33 +205,6 @@ public function getInputSource(): LocalInputSource
262205 return $ this ->inputSource ;
263206 }
264207
265- /**
266- * Extracts images from a page.
267- *
268- * @param array<BaseField<string|float|integer|boolean|Polygon>> $fields List of Fields to extract.
269- * @param integer $pageIndex The page index to extract, begins at 0.
270- * @param string $outputName Name of the created file.
271- * @param string $format The output format.
272- *
273- * @return array<ExtractedImage> An array of created images
274- */
275- protected function extractFromPage (array $ fields , int $ pageIndex , string $ outputName , string $ format = 'jpg ' ): array
276- {
277- $ extractedImages = [];
278-
279- $ i = 0 ;
280- foreach ($ fields as $ field ) {
281- $ filename = sprintf ('%s_page%d-%d.%s ' , $ outputName , $ pageIndex , $ i , $ format );
282- $ extractedImage = $ this ->extractImage ($ field , $ pageIndex , $ i , $ filename , $ format );
283- if (null !== $ extractedImage ) {
284- $ extractedImages [] = $ extractedImage ;
285- }
286- ++$ i ;
287- }
288-
289- return $ extractedImages ;
290- }
291-
292208 /**
293209 * Extracts an image from a set of coordinates.
294210 *
0 commit comments