Class ImageTransformer
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.transformer.AbstractDocumentTransformer
-
- com.norconex.importer.handler.transformer.impl.ImageTransformer
-
- All Implemented Interfaces:
IXMLConfigurable,IImporterHandler,IDocumentTransformer
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.Content-types
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.Image dimension format
For a list of supported image dimension formats, refer to
DimensionConverter.XML configuration usage:
<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>(field-matching expression)</fieldMatcher> <valueMatcher>(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>XML usage example:
<handler class="ImageTransformer" targetFormat="png"> <scale dimension="400x250"/> </handler>Usage example:
The above example converts images to PNG while scaling it to a maximum dimension of 400 pixels wide and 250 pixel high.
- Since:
- 3.0.0
- Author:
- Pascal Essiembre
- See Also:
ExternalHandler
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_TARGET_FORMAT
-
Constructor Summary
Constructors Constructor Description ImageTransformer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)RectanglegetCropRectangle()DoublegetRotateDegrees()DimensiongetScaleDimension()DoublegetScaleFactor()StringgetTargetFormat()inthashCode()booleanisScaleStretch()protected voidloadHandlerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected voidsaveHandlerToXML(XML xml)Saves configuration settings specific to the implementing class.voidsetCropRectangle(Rectangle cropRectangle)voidsetRotateDegrees(Double rotateDegrees)voidsetScaleDimension(Dimension scaleDimension)voidsetScaleFactor(Double scaleFactor)voidsetScaleStretch(boolean scaleStretch)voidsetTargetFormat(String targetFormat)StringtoString()protected voidtransformApplicableDocument(HandlerDoc doc, InputStream input, OutputStream output, ParseState parseState)voidtransformImage(MutableImage image)-
Methods inherited from class com.norconex.importer.handler.transformer.AbstractDocumentTransformer
transformDocument
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
-
-
-
Field Detail
-
DEFAULT_TARGET_FORMAT
public static final String DEFAULT_TARGET_FORMAT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTargetFormat
public String getTargetFormat()
-
setTargetFormat
public void setTargetFormat(String targetFormat)
-
isScaleStretch
public boolean isScaleStretch()
-
setScaleStretch
public void setScaleStretch(boolean scaleStretch)
-
getScaleFactor
public Double getScaleFactor()
-
setScaleFactor
public void setScaleFactor(Double scaleFactor)
-
getScaleDimension
public Dimension getScaleDimension()
-
setScaleDimension
public void setScaleDimension(Dimension scaleDimension)
-
getRotateDegrees
public Double getRotateDegrees()
-
setRotateDegrees
public void setRotateDegrees(Double rotateDegrees)
-
getCropRectangle
public Rectangle getCropRectangle()
-
setCropRectangle
public void setCropRectangle(Rectangle cropRectangle)
-
transformApplicableDocument
protected void transformApplicableDocument(HandlerDoc doc, InputStream input, OutputStream output, ParseState parseState) throws ImporterHandlerException
- Specified by:
transformApplicableDocumentin classAbstractDocumentTransformer- Throws:
ImporterHandlerException
-
transformImage
public void transformImage(MutableImage image)
-
loadHandlerFromXML
protected void loadHandlerFromXML(XML xml)
Description copied from class:AbstractImporterHandlerLoads configuration settings specific to the implementing class.- Specified by:
loadHandlerFromXMLin classAbstractImporterHandler- Parameters:
xml- XML configuration
-
saveHandlerToXML
protected void saveHandlerToXML(XML xml)
Description copied from class:AbstractImporterHandlerSaves configuration settings specific to the implementing class.- Specified by:
saveHandlerToXMLin classAbstractImporterHandler- Parameters:
xml- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractImporterHandler
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractImporterHandler
-
toString
public String toString()
- Overrides:
toStringin classAbstractImporterHandler
-
-