44
55namespace Mindee \Extraction ;
66
7+ use Exception ;
78use Mindee \Dependency \DependencyChecker ;
89use Mindee \Error \ErrorCode ;
910use Mindee \Error \MindeeGeometryException ;
1011use Mindee \Error \MindeeImageException ;
1112use Mindee \Error \MindeePDFException ;
1213use Mindee \Geometry \BBox ;
1314use Mindee \Geometry \BBoxUtils ;
15+ use Mindee \Geometry \Point ;
1416use Mindee \Geometry \Polygon ;
1517use Mindee \Input \LocalInputSource ;
1618use Mindee \V1 \Parsing \Standard \BaseField ;
@@ -129,11 +131,11 @@ public function getPageCount(): int
129131 /**
130132 * Extract multiple images on a given page from a list of fields having position data.
131133 *
132- * @param array $fields List of Fields to extract.
134+ * @param array<BaseField<string|float|integer|boolean|Polygon>> $fields List of Fields to extract.
133135 * @param integer $pageIndex The page index to extract, begins at 0.
134136 * @param null|string $outputName The base output filename, must have an image extension.
135137 *
136- * @return array a list of extracted images
138+ * @return array<ExtractedImage> a list of extracted images
137139 */
138140 public function extractImagesFromPage (array $ fields , int $ pageIndex , ?string $ outputName = null ): array
139141 {
@@ -144,12 +146,12 @@ public function extractImagesFromPage(array $fields, int $pageIndex, ?string $ou
144146 /**
145147 * Extracts images from a page.
146148 *
147- * @param array $polygons List of polygons to extract.
149+ * @param array<Polygon|array<Point>> $polygons List of polygons to extract.
148150 * @param integer $pageIndex The page index to extract, begins at 0.
149151 * @param null|string $filenamePrefix Output filename prefix.
150152 * @param null|string $format Save format for extracted images. Defaults to the original format.
151153 *
152- * @return array an array of created images
154+ * @return array<ExtractedImage> An array of created images
153155 * @throws MindeeImageException Throws if the image can't be processed.
154156 */
155157 public function extractPolygonsFromPage (
@@ -173,7 +175,7 @@ public function extractPolygonsFromPage(
173175 $ saveFormat
174176 );
175177 }
176- } catch (ImagickException $ e ) {
178+ } catch (Exception $ e ) {
177179 throw new MindeeImageException ($ e ->getMessage (), $ e ->getCode (), $ e );
178180 }
179181
@@ -205,16 +207,15 @@ public function extractPolygonFromPage(
205207 } catch (ImagickException $ e ) {
206208 throw new MindeeImageException ($ e ->getMessage (), $ e ->getCode (), $ e );
207209 }
208- $ filename ??= $ this ->filename ;
209210 $ format ??= $ this ->saveFormat ;
210- $ filename ??= sprintf ('%s.% s_page%d-%d.%s ' , $ filename, $ format , $ pageIndex , $ index , $ format );
211+ $ filename ??= sprintf ('%s_page%d-%d.%s ' , $ this -> filename , $ pageIndex , $ index , $ format );
211212 return new ExtractedImage ($ extractedImageData , $ filename , $ format , $ pageIndex , $ index );
212213 }
213214
214215 /**
215216 * Extracts a single image from a Position field.
216217 *
217- * @param BaseField $field The field to extract.
218+ * @param BaseField<string|float|integer|boolean|Polygon> $field The field to extract.
218219 * @param integer $pageIndex The page index to extract, begins at 0.
219220 * @param integer $index The index to use for naming the extracted image.
220221 * @param string $filename The output filename.
@@ -264,16 +265,15 @@ public function getInputSource(): LocalInputSource
264265 /**
265266 * Extracts images from a page.
266267 *
267- * @param array $fields List of Fields to extract.
268+ * @param array<BaseField<string|float|integer|boolean|Polygon>> $fields List of Fields to extract.
268269 * @param integer $pageIndex The page index to extract, begins at 0.
269270 * @param string $outputName Name of the created file.
270271 * @param string $format The output format.
271272 *
272- * @return array an array of created images
273+ * @return array<ExtractedImage> An array of created images
273274 */
274275 protected function extractFromPage (array $ fields , int $ pageIndex , string $ outputName , string $ format = 'jpg ' ): array
275276 {
276- $ format ??= $ this ->saveFormat ;
277277 $ extractedImages = [];
278278
279279 $ i = 0 ;
@@ -316,7 +316,7 @@ protected function extractImageFromBbox(BBox $bbox, int|float $pageIndex): Imagi
316316 * Splits the filename into name and extension.
317317 *
318318 * @param string $filename Name of the file.
319- * @return array An array containing the name and extension of the file.
319+ * @return array{0: string, 1: string} An array containing the name and extension of the file.
320320 */
321321 protected static function splitNameStrict (string $ filename ): array
322322 {
0 commit comments