|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.coobird.thumbnailator.makers.ThumbnailMaker net.coobird.thumbnailator.makers.FixedSizeThumbnailMaker
public final class FixedSizeThumbnailMaker
A ThumbnailMaker
which resizes an image to a specified dimension
when producing a thumbnail.
Optionally, if the aspect ratio of the thumbnail is to be maintained the same
as the original image (by calling the keepAspectRatio(boolean)
method with the value true
), then the dimensions specified by the
size(int, int)
method, FixedSizeThumbnailMaker(int, int)
or
FixedSizeThumbnailMaker(int, int, boolean)
constructor will be used
as the maximum constraint of dimensions of the thumbnail.
In other words, when the aspect ratio is to be kept constant, then thumbnails which are created will be sized to fit inside the dimensions specified by the size parameter.
Upon calculating the size of the thumbnail, if any of the dimensions are
0
, then that dimension will be promoted to 1
, regardless of
whether the aspect ratio of the original image is to be maintained. This will
lead to some thumbnails not preserving the aspect ratio of the original
image, even if keepAspectRatio(boolean)
has been true
.
BufferedImage img = ImageIO.read(new File("sourceImage.jpg")); BufferedImage thumbnail = new FixedSizeThumbnailMaker() .size(200, 200) .keepAspectRatio(true) .make(img);
Constructor Summary | |
---|---|
FixedSizeThumbnailMaker()
Creates a FixedSizeThumbnailMaker . |
|
FixedSizeThumbnailMaker(int width,
int height)
Creates a FixedSizeThumbnailMaker which creates thumbnails
with the specified size. |
|
FixedSizeThumbnailMaker(int width,
int height,
boolean aspectRatio)
Creates a FixedSizeThumbnailMaker which creates thumbnails
with the specified size. |
|
FixedSizeThumbnailMaker(int width,
int height,
boolean aspectRatio,
boolean fit)
Creates a FixedSizeThumbnailMaker which creates thumbnails
with the specified size. |
Method Summary | |
---|---|
FixedSizeThumbnailMaker |
fitWithinDimensions(boolean fit)
Sets whether or not the thumbnail should fit within the specified dimensions. |
FixedSizeThumbnailMaker |
keepAspectRatio(boolean keep)
Sets whether or not the thumbnail is to maintain the aspect ratio of the original image. |
BufferedImage |
make(BufferedImage img)
Makes a thumbnail. |
FixedSizeThumbnailMaker |
size(int width,
int height)
Sets the size of the thumbnail to produce. |
Methods inherited from class net.coobird.thumbnailator.makers.ThumbnailMaker |
---|
defaultImageType, defaultResizer, defaultResizerFactory, imageType, resizer, resizerFactory |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FixedSizeThumbnailMaker()
FixedSizeThumbnailMaker
.
The size of the resulting thumbnail, and whether or not the aspect ratio of the original image should be maintained in the thumbnail must be set before this instance is able to produce thumbnails.
public FixedSizeThumbnailMaker(int width, int height)
FixedSizeThumbnailMaker
which creates thumbnails
with the specified size.
Before this instance is able to produce thumbnails, whether or not the
aspect ratio of the original image should be maintained in the thumbnail
must be specified by calling the keepAspectRatio(boolean)
method.
width
- The width of the thumbnail to produce.height
- The height of the thumbnails to produce.public FixedSizeThumbnailMaker(int width, int height, boolean aspectRatio)
FixedSizeThumbnailMaker
which creates thumbnails
with the specified size. Whether or not the aspect ratio of the original
image should be preserved by the thumbnail is also specified at
instantiation.
width
- The width of the thumbnail to produce.height
- The height of the thumbnails to produce.aspectRatio
- Whether or not to maintain the aspect ratio in the
thumbnail the same as the original image.
If true
is specified, then the
thumbnail image will have the same aspect ratio
as the original image.
public FixedSizeThumbnailMaker(int width, int height, boolean aspectRatio, boolean fit)
FixedSizeThumbnailMaker
which creates thumbnails
with the specified size. Whether or not the aspect ratio of the original
image should be preserved by the thumbnail, and whether to fit the
thumbnail within the given dimensions is also specified at
instantiation.
width
- The width of the thumbnail to produce.height
- The height of the thumbnails to produce.aspectRatio
- Whether or not to maintain the aspect ratio in the
thumbnail the same as the original image.
If true
is specified, then the
thumbnail image will have the same aspect ratio
as the original image.
fit
- Whether or not to fit the thumbnail within the
specified dimensions.
If true
is specified, then the thumbnail
will be sized to fit within the specified
width
and height
.
Method Detail |
---|
public FixedSizeThumbnailMaker size(int width, int height)
width
- The width of the thumbnail to produce.height
- The height of the thumbnails to produce.
IllegalStateException
- If the size has already
been previously set, or if the
width
or height
is less
than or equal to zero.public FixedSizeThumbnailMaker keepAspectRatio(boolean keep)
keep
- Whether or not to maintain the aspect ratio in the
thumbnail the same as the original image.
If true
is specified, then the
thumbnail image will have the same aspect ratio
as the original image.
IllegalStateException
- If whether to keep the aspect ratio has
already been previously set.public FixedSizeThumbnailMaker fitWithinDimensions(boolean fit)
When the dimensions of a thumbnail will exceed the specified dimensions,
with the aspect ratio of the original being preserved, then if this
method was called with false
, then the resulting thumbnail will
have the larger dimension align with the specified dimension, and the
other will exceed the given dimension.
When keepAspectRatio(boolean)
is false
, then calling
this method with true
or false
makes no difference, as
the thumbnail dimensions will be exactly the given dimensions.
fit
- Whether or not to maintain the aspect ratio in the
thumbnail the same as the original image.
If true
is specified, then the
thumbnail image will have the same aspect ratio
as the original image.
IllegalStateException
- If whether to keep the aspect ratio has
already been previously set.public BufferedImage make(BufferedImage img)
ThumbnailMaker
make
in class ThumbnailMaker
img
- The source image.
ThumbnailMaker
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |