Class ThumbnailParameterBuilder
- java.lang.Object
-
- net.coobird.thumbnailator.builders.ThumbnailParameterBuilder
-
public final class ThumbnailParameterBuilder extends java.lang.ObjectA builder for generating
ThumbnailParameter.The default values assigned to the
ThumbnailParametercreated by theThumbnailParameterBuilderare as follows:- width
- Unassigned. Must be set by the
size(int, int)method. - height
- Unassigned. Must be set by the
size(int, int)method. - scaling factor
- Unassigned. Must be set by the
scale(double)method orscale(double, double)method. - source region
- Uses the entire source image.
- image type
- See
ThumbnailParameter.DEFAULT_IMAGE_TYPE. Same asBufferedImage.TYPE_INT_ARGB. - aspect ratio
- Maintain the aspect ratio of the original image.
- output quality
- See
ThumbnailParameter.DEFAULT_QUALITY. - output format
- See
ThumbnailParameter.ORIGINAL_FORMAT. Maintains the same image format as the original image. - output format type
- See
ThumbnailParameter.DEFAULT_FORMAT_TYPE. Uses the default format type of the codec used to create the thumbnail image. - image filters
- None.
- resizer factory
DefaultResizerFactoryis used.- resizer
- The default
Resizerreturned by theResizerFactory. - use of Exif metadata for orientation
- Use the Exif metadata to determine the orientation of the thumbnail.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ImageFilter>filtersprivate booleanfitWithinDimensionsprivate intheightprivate doubleheightScalingFactorprivate intimageTypeprivate booleankeepAspectRatioprivate ResizerFactoryresizerFactoryprivate RegionsourceRegionprivate java.lang.StringthumbnailFormatprivate java.lang.StringthumbnailFormatTypeprivate floatthumbnailQualityprivate static intUNINITIALIZEDprivate booleanuseExifOrientationprivate intwidthprivate doublewidthScalingFactor
-
Constructor Summary
Constructors Constructor Description ThumbnailParameterBuilder()Creates an instance of aThumbnailParameterBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThumbnailParameterbuild()Returns aThumbnailParameterfrom the parameters which are currently set.ThumbnailParameterBuilderfilters(java.util.List<ImageFilter> filters)Sets theImageFilters to apply to the thumbnail.ThumbnailParameterBuilderfitWithinDimensions(boolean fit)Sets whether or not the thumbnail should fit within the specified dimensions.ThumbnailParameterBuilderformat(java.lang.String format)Sets the output format of the thumbnail.ThumbnailParameterBuilderformatType(java.lang.String formatType)Sets the output format type of the thumbnail.ThumbnailParameterBuilderimageType(int type)Sets the image type fo the thumbnail.ThumbnailParameterBuilderkeepAspectRatio(boolean keep)Sets whether or not the thumbnail is to maintain the aspect ratio of the original image.ThumbnailParameterBuilderquality(float quality)Sets the compression quality setting of the thumbnail.ThumbnailParameterBuilderregion(Region sourceRegion)Sets the region of the source image to use when creating a thumbnail.ThumbnailParameterBuilderresizer(Resizer resizer)Sets theResizerto use when performing the resizing operation to create the thumbnail.ThumbnailParameterBuilderresizerFactory(ResizerFactory resizerFactory)Sets theResizerFactoryto use to obtain aResizerwhen performing the resizing operation to create the thumbnail.ThumbnailParameterBuilderscale(double scalingFactor)Sets the scaling factor of the thumbnail.ThumbnailParameterBuilderscale(double widthScalingFactor, double heightScalingFactor)Sets the scaling factor of the thumbnail.ThumbnailParameterBuildersize(int width, int height)Sets the size of the thumbnail.ThumbnailParameterBuildersize(java.awt.Dimension size)Sets the size of the thumbnail.ThumbnailParameterBuilderuseExifOrientation(boolean use)Sets whether or not the Exif metadata should be used to determine the orientation of the thumbnail.
-
-
-
Field Detail
-
UNINITIALIZED
private static final int UNINITIALIZED
- See Also:
- Constant Field Values
-
width
private int width
-
height
private int height
-
widthScalingFactor
private double widthScalingFactor
-
heightScalingFactor
private double heightScalingFactor
-
imageType
private int imageType
-
keepAspectRatio
private boolean keepAspectRatio
-
thumbnailQuality
private float thumbnailQuality
-
thumbnailFormat
private java.lang.String thumbnailFormat
-
thumbnailFormatType
private java.lang.String thumbnailFormatType
-
filters
private java.util.List<ImageFilter> filters
-
resizerFactory
private ResizerFactory resizerFactory
-
sourceRegion
private Region sourceRegion
-
fitWithinDimensions
private boolean fitWithinDimensions
-
useExifOrientation
private boolean useExifOrientation
-
-
Constructor Detail
-
ThumbnailParameterBuilder
public ThumbnailParameterBuilder()
Creates an instance of aThumbnailParameterBuilder.
-
-
Method Detail
-
imageType
public ThumbnailParameterBuilder imageType(int type)
Sets the image type fo the thumbnail.- Parameters:
type- The image type of the thumbnail.- Returns:
- A reference to this object.
-
size
public ThumbnailParameterBuilder size(java.awt.Dimension size)
Sets the size of the thumbnail.- Parameters:
size- The dimensions of the thumbnail.- Returns:
- A reference to this object.
-
size
public ThumbnailParameterBuilder size(int width, int height)
Sets the size of the thumbnail.- Parameters:
width- The width of the thumbnail.height- The height of the thumbnail.- Returns:
- A reference to this object.
- Throws:
java.lang.IllegalArgumentException- If the widht or height is less than 0.
-
scale
public ThumbnailParameterBuilder scale(double scalingFactor)
Sets the scaling factor of the thumbnail.- Parameters:
scalingFactor- The scaling factor of the thumbnail.- Returns:
- A reference to this object.
- Throws:
java.lang.IllegalArgumentException- If the scaling factor is not a rational number, or if it is less than0.0.
-
scale
public ThumbnailParameterBuilder scale(double widthScalingFactor, double heightScalingFactor)
Sets the scaling factor of the thumbnail.- Parameters:
widthScalingFactor- The scaling factor to use for the width when creating the thumbnail.heightScalingFactor- The scaling factor to use for the height when creating the thumbnail.- Returns:
- A reference to this object.
- Throws:
java.lang.IllegalArgumentException- If the scaling factor is not a rational number, or if it is less than0.0.- Since:
- 0.3.10
-
region
public ThumbnailParameterBuilder region(Region sourceRegion)
Sets the region of the source image to use when creating a thumbnail.- Parameters:
sourceRegion- The region of the source image to use when creating a thumbnail.- Returns:
- A reference to this object.
- Since:
- 0.3.4
-
keepAspectRatio
public ThumbnailParameterBuilder keepAspectRatio(boolean keep)
Sets whether or not the thumbnail is to maintain the aspect ratio of the original image.- Parameters:
keep-trueif the aspect ratio of the original image is to be maintained in the thumbnail,falseotherwise.- Returns:
- A reference to this object.
-
quality
public ThumbnailParameterBuilder quality(float quality)
Sets the compression quality setting of the thumbnail.An acceptable value is in the range of
0.0fto1.0f, where0.0fis for the lowest quality setting and1.0ffor the highest quality setting.If the default compression quality is to be used, then the value
ThumbnailParameter.DEFAULT_QUALITYshould be used.- Parameters:
quality- The compression quality setting of the thumbnail.- Returns:
- A reference to this object.
-
format
public ThumbnailParameterBuilder format(java.lang.String format)
Sets the output format of the thumbnail.- Parameters:
format- The output format of the thumbnail.- Returns:
- A reference to this object.
-
formatType
public ThumbnailParameterBuilder formatType(java.lang.String formatType)
Sets the output format type of the thumbnail.- Parameters:
formatType- The output format type of the thumbnail.- Returns:
- A reference to this object.
-
filters
public ThumbnailParameterBuilder filters(java.util.List<ImageFilter> filters)
Sets theImageFilters to apply to the thumbnail.These filters will be applied after the original image is resized.
- Parameters:
filters- The output format type of the thumbnail.- Returns:
- A reference to this object.
-
resizer
public ThumbnailParameterBuilder resizer(Resizer resizer)
Sets theResizerto use when performing the resizing operation to create the thumbnail.Calling this method after
resizerFactory(ResizerFactory)will cause theResizerFactoryused by the resultingThumbnailParameterto only return the specifiedResizer.- Parameters:
resizer- TheResizerto use when creating the thumbnail.- Returns:
- A reference to this object.
-
resizerFactory
public ThumbnailParameterBuilder resizerFactory(ResizerFactory resizerFactory)
Sets theResizerFactoryto use to obtain aResizerwhen performing the resizing operation to create the thumbnail.Calling this method after
resizer(Resizer)could result inResizers not specified in theresizermethod to be used when creating thumbnails.- Parameters:
resizerFactory- TheResizerFactoryto use when obtaining aResizerto create the thumbnail.- Returns:
- A reference to this object.
- Since:
- 0.4.0
-
fitWithinDimensions
public ThumbnailParameterBuilder fitWithinDimensions(boolean fit)
Sets whether or not the thumbnail should fit within the specified dimensions.- Parameters:
fit-trueif the thumbnail should be sized to fit within the specified dimensions, if the thumbnail is going to exceed those dimensions.- Returns:
- A reference to this object.
- Since:
- 0.4.0
-
useExifOrientation
public ThumbnailParameterBuilder useExifOrientation(boolean use)
Sets whether or not the Exif metadata should be used to determine the orientation of the thumbnail.- Parameters:
use-trueif the Exif metadata should be used to determine the orientation of the thumbnail,falseotherwise.- Returns:
- A reference to this object.
- Since:
- 0.4.3
-
build
public ThumbnailParameter build()
Returns aThumbnailParameterfrom the parameters which are currently set.This method will throw a
IllegalArgumentExceptionrequired parameters for theThumbnailParameterhave not been set.- Returns:
- A
ThumbnailParameterwith parameters set through the use of this builder. - Throws:
java.lang.IllegalStateException- If neither the size nor the scaling factor has been set.
-
-