Documentation

ImageExtractor extends ImageExtractor
in package

Wrapper class for V1 of the BaseImageExtractor.

Table of Contents

Constants

DEFAULT_PDF_DPI  : mixed = 300.0
Resolution PDF pages are rendered at before cropping, in dots per inch. Images are cropped at their own resolution.

Properties

$pageCount  : int
$filename  : string
$inputSource  : LocalInputSource
$pageImages  : array<string|int, Image>
$pdfDpi  : float
$saveFormat  : string
$sourceData  : string

Methods

__construct()  : mixed
extractImage()  : null|ExtractedImage
Extracts a single image from a Position field.
extractImagesFromPage()  : array<string|int, ExtractedImage>
Extract multiple images on a given page from a list of fields having position data.
extractMultipleImagesFromSource()  : array<string|int, ExtractedImage>
Extracts images from a page.
extractPolygonFromPage()  : ExtractedImage
Extracts a cropped portion from an image.
getInputSource()  : LocalInputSource
Getter for the local input source.
cropPolygons()  : array<string|int, Image>
Crops every polygon's bounding box from a page, in a single native call.
encodeCrop()  : ExtractedImage
Encodes a cropped image and wraps it.
extractFromPage()  : array<string|int, ExtractedImage>
Extracts images from a page.
fieldPolygon()  : Polygon
Returns a field's position data: its polygon, bounding box, quadrangle or rectangle, whichever comes first.
polygonToPairs()  : array<string|int, array{0: float, 1: float}>
Converts a polygon to the `[[x, y], ...]` shape the native extension expects.

Constants

DEFAULT_PDF_DPI

Resolution PDF pages are rendered at before cropping, in dots per inch. Images are cropped at their own resolution.

public mixed DEFAULT_PDF_DPI = 300.0

Properties

$pageCount

public int $pageCount

Number of pages in the document.

$pageImages

protected array<string|int, Image> $pageImages = []

Array of extracted page images.

$saveFormat

protected string $saveFormat

Format to save the image as.

$sourceData

protected string $sourceData

Contents of the input source, read once: some sources can only be read once.

Methods

__construct()

public __construct(LocalInputSource $localInput[, null|string $saveFormat = null ][, float $pdfDpi = self::DEFAULT_PDF_DPI ]) : mixed
Parameters
$localInput : LocalInputSource

Local input, accepts all compatible formats.

$saveFormat : null|string = null

Save format, will be coerced to jpg by default.

$pdfDpi : float = self::DEFAULT_PDF_DPI

Resolution PDF pages are rendered at before cropping; ignored for images.

Tags
throws
MindeePdfException

Throws if PDF operations aren't supported, or if the file can't be read, respectively.

extractImage()

Extracts a single image from a Position field.

public extractImage(BaseField<string|int, string|float|int|bool|Polygon> $field, int $pageIndex, int $index, string $filename, string $format) : null|ExtractedImage
Parameters
$field : BaseField<string|int, string|float|int|bool|Polygon>

The field to extract.

$pageIndex : int

The page index to extract, begins at 0.

$index : int

The index to use for naming the extracted image.

$filename : string

The output filename.

$format : string

The output format.

Tags
throws
MindeeGeometryException

Throws if a field does not contain positional data.

Return values
null|ExtractedImage —

The extracted image, or null if the field does not have valid position data.

extractImagesFromPage()

Extract multiple images on a given page from a list of fields having position data.

public extractImagesFromPage(array<string|int, BaseField<string|int, string|float|int|bool|Polygon>> $fields, int $pageIndex[, null|string $outputName = null ]) : array<string|int, ExtractedImage>
Parameters
$fields : array<string|int, BaseField<string|int, string|float|int|bool|Polygon>>

List of Fields to extract.

$pageIndex : int

The page index to extract, begins at 0.

$outputName : null|string = null

The base output filename, must have an image extension.

Return values
array<string|int, ExtractedImage> —

a list of extracted images

extractMultipleImagesFromSource()

Extracts images from a page.

public extractMultipleImagesFromSource(array<string|int, Polygon|array<string|int, Point>> $polygons, int $pageIndex[, null|string $filenamePrefix = null ][, null|string $format = null ][, null|array<string|int, int> $indexes = null ]) : array<string|int, ExtractedImage>
Parameters
$polygons : array<string|int, Polygon|array<string|int, Point>>

List of polygons to extract.

$pageIndex : int

The page index to extract, begins at 0.

$filenamePrefix : null|string = null

Output filename prefix.

$format : null|string = null

Save format for extracted images. Defaults to the original format.

$indexes : null|array<string|int, int> = null

Index of each polygon, used in its image's file name and index, in the same order as the polygons. Defaults to 0, 1, 2...

Tags
throws
MindeeImageException

Throws if the image can't be processed.

Return values
array<string|int, ExtractedImage> —

An array of created images

extractPolygonFromPage()

Extracts a cropped portion from an image.

public extractPolygonFromPage(Polygon|array<string|int, Point> $polygon, int $pageIndex, int $index[, null|string $filename = null ][, null|string $format = null ]) : ExtractedImage
Parameters
$polygon : Polygon|array<string|int, Point>

Polygon to extract.

$pageIndex : int

Page index to extract from.

$index : int

Index to use for naming the extracted image.

$filename : null|string = null

Output filename.

$format : null|string = null

Output format.

Tags
throws
MindeeImageException

Throws if the image can't be processed.

Return values
ExtractedImage —

Extracted image data.

cropPolygons()

Crops every polygon's bounding box from a page, in a single native call.

protected cropPolygons(array<string|int, Polygon|array<string|int, Point>> $polygons, int $pageIndex) : array<string|int, Image>
Parameters
$polygons : array<string|int, Polygon|array<string|int, Point>>

Polygons to crop.

$pageIndex : int

Page index, begins at 0.

Tags
throws
MindeeImageException

Throws if the page or polygons can't be processed.

Return values
array<string|int, Image> —

One image per polygon, in the same order.

encodeCrop()

Encodes a cropped image and wraps it.

protected encodeCrop(Image $crop, int $pageIndex, int $index, string $filename, string $format) : ExtractedImage
Parameters
$crop : Image
$pageIndex : int
$index : int
$filename : string
$format : string
Tags
throws
MindeeImageException

Throws if encoding fails.

Return values
ExtractedImage

extractFromPage()

Extracts images from a page.

protected extractFromPage(array<string|int, BaseField<string|int, string|float|int|bool|Polygon>> $fields, int $pageIndex, string $outputName[, string $format = 'jpg' ]) : array<string|int, ExtractedImage>
Parameters
$fields : array<string|int, BaseField<string|int, string|float|int|bool|Polygon>>

List of Fields to extract.

$pageIndex : int

The page index to extract, begins at 0.

$outputName : string

Name of the created file.

$format : string = 'jpg'

The output format.

Return values
array<string|int, ExtractedImage> —

An array of created images

fieldPolygon()

Returns a field's position data: its polygon, bounding box, quadrangle or rectangle, whichever comes first.

protected static fieldPolygon(BaseField<string|int, string|float|int|bool|Polygon> $field) : Polygon
Parameters
$field : BaseField<string|int, string|float|int|bool|Polygon>

The field.

Tags
throws
MindeeGeometryException

Throws if the field does not contain positional data.

Return values
Polygon

polygonToPairs()

Converts a polygon to the `[[x, y], ...]` shape the native extension expects.

protected static polygonToPairs(Polygon|array<string|int, Point> $polygon) : array<string|int, array{0: float, 1: float}>
Parameters
$polygon : Polygon|array<string|int, Point>

Polygon or list of points.

Return values
array<string|int, array{0: float, 1: float}>
On this page

Search results