public class ImageTransformer extends AbstractDocumentTransformer
Transforms an image using common image operations.
This class should only be used as a pre-parsing handler, on image files.
It may also be appropriate to disable parsing of those images if you
want to keep the transformed version intact. This can be done with
GenericDocumentParserFactory
.
By default, this filter is restricted to (applies only to) documents matching
the restrictions returned by
CommonRestrictions.imageIOStandardContentTypes(String)
.
You can specify your own content types if you know they represent a supported
image.
For a list of supported image dimension formats, refer to
DimensionConverter
.
<handler
class="com.norconex.importer.handler.transformer.impl.ImageTransformer"
targetFormat="(jpg, png, gif, bmp, wbmp, or other supported format)">
<!-- multiple "restrictTo" tags allowed (only one needs to match) -->
<restrictTo>
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(field-matching expression)
</fieldMatcher>
<valueMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(value-matching expression)
</valueMatcher>
</restrictTo>
<scale
stretch="[false|true]"
factor="(decimal value ratio factor, default is 1)"
dimension="(target dimension, in pixels, format: [width]x[height])"/>
<rotate
degrees="(-360 to 360)"/>
<crop
x="(top-left x-axis, default 0)"
y="(top-left y-axis, default 0)"
dimension="(crop dimension, in pixels, format: [width]x[height])"/>
</handler>
<handler
class="ImageTransformer"
targetFormat="png">
<scale
dimension="400x250"/>
</handler>
The above example converts images to PNG while scaling it to a maximum dimension of 400 pixels wide and 250 pixel high.
ExternalHandler
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_TARGET_FORMAT |
Constructor and Description |
---|
ImageTransformer() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
Rectangle |
getCropRectangle() |
Double |
getRotateDegrees() |
Dimension |
getScaleDimension() |
Double |
getScaleFactor() |
String |
getTargetFormat() |
int |
hashCode() |
boolean |
isScaleStretch() |
protected void |
loadHandlerFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveHandlerToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
void |
setCropRectangle(Rectangle cropRectangle) |
void |
setRotateDegrees(Double rotateDegrees) |
void |
setScaleDimension(Dimension scaleDimension) |
void |
setScaleFactor(Double scaleFactor) |
void |
setScaleStretch(boolean scaleStretch) |
void |
setTargetFormat(String targetFormat) |
String |
toString() |
protected void |
transformApplicableDocument(HandlerDoc doc,
InputStream input,
OutputStream output,
ParseState parseState) |
void |
transformImage(MutableImage image) |
transformDocument
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public static final String DEFAULT_TARGET_FORMAT
public String getTargetFormat()
public void setTargetFormat(String targetFormat)
public boolean isScaleStretch()
public void setScaleStretch(boolean scaleStretch)
public Double getScaleFactor()
public void setScaleFactor(Double scaleFactor)
public Dimension getScaleDimension()
public void setScaleDimension(Dimension scaleDimension)
public Double getRotateDegrees()
public void setRotateDegrees(Double rotateDegrees)
public Rectangle getCropRectangle()
public void setCropRectangle(Rectangle cropRectangle)
protected void transformApplicableDocument(HandlerDoc doc, InputStream input, OutputStream output, ParseState parseState) throws ImporterHandlerException
transformApplicableDocument
in class AbstractDocumentTransformer
ImporterHandlerException
public void transformImage(MutableImage image)
protected void loadHandlerFromXML(XML xml)
AbstractImporterHandler
loadHandlerFromXML
in class AbstractImporterHandler
xml
- XML configurationprotected void saveHandlerToXML(XML xml)
AbstractImporterHandler
saveHandlerToXML
in class AbstractImporterHandler
xml
- the XMLpublic boolean equals(Object other)
equals
in class AbstractImporterHandler
public int hashCode()
hashCode
in class AbstractImporterHandler
public String toString()
toString
in class AbstractImporterHandler
Copyright © 2009–2023 Norconex Inc.. All rights reserved.