ImageTransformer
Transforms an image using common image operations.
Notes
Scales, rotates, crops and converts images, replacing the document content with
the transformed image. Operations are applied in that order: scale, rotate,
crop, so crop coordinates refer to the image as scaling and rotation left
it.
Use it as a pre-parse handler, before any parser runs. If you want the transformed image kept as-is, make sure no parser handler runs on these documents afterwards — parsing replaces the binary content with extracted text.
By default only the image formats
ImageIO
supports are processed; see contentTypeMatcher.
Examples
Converts images to PNG while scaling them to fit within 400 × 250 pixels.
- YAML
- JSON
- XML
handler:
class: ImageTransformer
targetFormat: png
scale:
width: 400
height: 250
{
"handler": {
"class": "ImageTransformer",
"targetFormat": "png",
"scale": {
"width": 400,
"height": 250
}
}
}
<handler class="ImageTransformer">
<targetFormat>png</targetFormat>
<scale>
<width>400</width>
<height>250</height>
</scale>
</handler>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
class: ImageTransformer
contentTypeMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
crop:
height: 0
width: 0
x: 0
y: 0
label: string
rotation: 0
scale:
factor: 0
height: 0
stretch: false
width: 0
targetFormat: string
{
"class": "ImageTransformer",
"contentTypeMatcher": {
"ignoreCase": false,
"ignoreDiacritic": false,
"matchEmpty": false,
"method": "BASIC",
"negateMatches": false,
"partial": false,
"pattern": "string",
"replaceAll": false,
"trim": false
},
"crop": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"label": "string",
"rotation": 0,
"scale": {
"factor": 0,
"height": 0,
"stretch": false,
"width": 0
},
"targetFormat": "string"
}
<handler>
<class>ImageTransformer</class>
<contentTypeMatcher>
<ignoreCase>false</ignoreCase>
<ignoreDiacritic>false</ignoreDiacritic>
<matchEmpty>false</matchEmpty>
<method>BASIC</method>
<negateMatches>false</negateMatches>
<partial>false</partial>
<pattern>string</pattern>
<replaceAll>false</replaceAll>
<trim>false</trim>
</contentTypeMatcher>
<crop>
<height>0</height>
<width>0</width>
<x>0</x>
<y>0</y>
</crop>
<label>string</label>
<rotation>0</rotation>
<scale>
<factor>0</factor>
<height>0</height>
<stretch>false</stretch>
<width>0</width>
</scale>
<targetFormat>string</targetFormat>
</handler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
contentTypeMatcher | TextMatcher | No | TextMatcher |
crop | Crop | No | Crop |
label | string | No | - |
rotation | number | No | - |
scale | Scale | No | Scale |
targetFormat | string | No | png |
Property Details
contentTypeMatcher
The content types this handler applies to. Documents of any other type pass through untouched. Defaults to the standard ImageIO-readable types (JPEG, PNG, GIF, BMP, WBMP), so widen it only for a format you know ImageIO can read.
crop
Region of the image to keep, given as a top-left corner plus a size. Applied after scaling and rotation. See Crop.
label
An optional, user-supplied label for this step in the importer pipeline. It has no effect on processing — it exists purely to help identify this step, for example in large configurations or in the visual configurator.
rotation
Rotation angle in degrees, from -360 to 360. Positive values rotate
clockwise. Applied after scaling and before cropping.
scale
Target size or ratio for the image, and whether its aspect ratio may be distorted to reach it. Applied first. See Scale.
targetFormat
Format the transformed image is written in — png (the default), jpg, gif,
bmp, wbmp, or any other format ImageIO can write. Set it to convert images
as well as resize them.