Skip to main content

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.

handler:
class: ImageTransformer
targetFormat: png
scale:
width: 400
height: 250

Usage

Full configuration skeleton, with every option and its default
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

Properties

PropertyTypeRequiredDefault
contentTypeMatcherTextMatcherNoTextMatcher
cropCropNoCrop
labelstringNo-
rotationnumberNo-
scaleScaleNoScale
targetFormatstringNopng

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.