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.