Class Thumbnailator
- java.lang.Object
-
- net.coobird.thumbnailator.Thumbnailator
-
public final class Thumbnailator extends java.lang.ObjectThis class provides static utility methods which perform generation of thumbnails using Thumbnailator.When images are resized, the aspect ratio of the images are preserved.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateThumbnailator()This class is not intended to be instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.image.BufferedImagecreateThumbnail(java.awt.image.BufferedImage img, int width, int height)Creates a thumbnail.static java.awt.ImagecreateThumbnail(java.awt.Image img, int width, int height)Creates a thumbnail from anImage.static java.awt.image.BufferedImagecreateThumbnail(java.io.File f, int width, int height)Creates a thumbnail from an image file, and returns as aBufferedImage.static voidcreateThumbnail(java.io.File inFile, java.io.File outFile, int width, int height)Creates a thumbnail from an source image and writes the thumbnail to a destination file.static voidcreateThumbnail(java.io.InputStream is, java.io.OutputStream os, int width, int height)Creates a thumbnail from image data streamed from anInputStreamand streams the data out to anOutputStream.static voidcreateThumbnail(java.io.InputStream is, java.io.OutputStream os, java.lang.String format, int width, int height)Creates a thumbnail from image data streamed from anInputStreamand streams the data out to anOutputStream, with the specified format for the output data.static voidcreateThumbnail(ThumbnailTask<?,?> task)Creates a thumbnail from parameters specified in aThumbnailTask.static voidcreateThumbnails(java.util.Collection<? extends java.io.File> files, Rename rename, int width, int height)Creates thumbnails from a specifiedCollectionofFiles.static java.util.Collection<java.io.File>createThumbnailsAsCollection(java.util.Collection<? extends java.io.File> files, Rename rename, int width, int height)Creates thumbnails from a specifiedCollectionofFiles.private static booleanhasSwapDimensionsFilter(java.util.List<ImageFilter> imageFilters)private static voidvalidateDimensions(int width, int height)Performs validation on the specified dimensions.
-
-
-
Method Detail
-
createThumbnail
public static void createThumbnail(ThumbnailTask<?,?> task) throws java.io.IOException
Creates a thumbnail from parameters specified in aThumbnailTask.- Parameters:
task- AThumbnailTaskto execute.- Throws:
java.io.IOException- Thrown when a problem occurs when creating a thumbnail.
-
hasSwapDimensionsFilter
private static boolean hasSwapDimensionsFilter(java.util.List<ImageFilter> imageFilters)
-
createThumbnail
public static java.awt.image.BufferedImage createThumbnail(java.awt.image.BufferedImage img, int width, int height)Creates a thumbnail.The resulting thumbnail uses the default image type.
When the image is resized, the aspect ratio will be preserved.
When the specified dimensions does not have the same aspect ratio as the source image, the specified dimensions will be used as the absolute boundary of the thumbnail.
For example, if the source image of 100 pixels by 100 pixels, and the desired thumbnail size is 50 pixels by 100 pixels, then the resulting thumbnail will be 50 pixels by 50 pixels, as the constraint will be 50 pixels for the width, and therefore, by preserving the aspect ratio, the height will be required to be 50 pixels.
- Parameters:
img- The source image.width- The width of the thumbnail.height- The height of the thumbnail.- Returns:
- Resulting thumbnail.
-
createThumbnail
public static void createThumbnail(java.io.File inFile, java.io.File outFile, int width, int height) throws java.io.IOExceptionCreates a thumbnail from an source image and writes the thumbnail to a destination file.The image format to use for the thumbnail will be determined from the file extension. However, if the image format cannot be determined, then, the same image format as the original image will be used when writing the thumbnail.
- Parameters:
inFile- TheFilefrom which image data is read.outFile- TheFileto which thumbnail is written.width- The width of the thumbnail.height- The height of the thumbnail.- Throws:
java.io.IOException- Thrown when a problem occurs when reading fromFilerepresenting an image file.
-
createThumbnail
public static java.awt.image.BufferedImage createThumbnail(java.io.File f, int width, int height) throws java.io.IOExceptionCreates a thumbnail from an image file, and returns as aBufferedImage.- Parameters:
f- TheFilefrom which image data is read.width- The width of the thumbnail.height- The height of the thumbnail.- Returns:
- The thumbnail image as a
BufferedImage. - Throws:
java.io.IOException- Thrown when a problem occurs when reading fromFilerepresenting an image file.
-
createThumbnail
public static java.awt.Image createThumbnail(java.awt.Image img, int width, int height)Creates a thumbnail from anImage.The resulting
BufferedImageuses the default image type.When the image is resized, the aspect ratio will be preserved.
When the specified dimensions does not have the same aspect ratio as the source image, the specified dimensions will be used as the absolute boundary of the thumbnail.
- Parameters:
img- The source image.width- The width of the thumbnail.height- The height of the thumbnail.- Returns:
- The thumbnail image as an
Image.
-
createThumbnail
public static void createThumbnail(java.io.InputStream is, java.io.OutputStream os, int width, int height) throws java.io.IOExceptionCreates a thumbnail from image data streamed from anInputStreamand streams the data out to anOutputStream.The thumbnail will be stored in the same format as the original image.
- Parameters:
is- TheInputStreamfrom which to obtain image data.os- TheOutputStreamto send thumbnail data to.width- The width of the thumbnail.height- The height of the thumbnail.- Throws:
java.io.IOException- Thrown when a problem occurs when reading fromFilerepresenting an image file.
-
createThumbnail
public static void createThumbnail(java.io.InputStream is, java.io.OutputStream os, java.lang.String format, int width, int height) throws java.io.IOExceptionCreates a thumbnail from image data streamed from anInputStreamand streams the data out to anOutputStream, with the specified format for the output data.- Parameters:
is- TheInputStreamfrom which to obtain image data.os- TheOutputStreamto send thumbnail data to.format- The image format to use to store the thumbnail data.width- The width of the thumbnail.height- The height of the thumbnail.- Throws:
java.io.IOException- Thrown when a problem occurs when reading fromFilerepresenting an image file.java.lang.IllegalArgumentException- If the specified output format is not supported.
-
createThumbnailsAsCollection
public static java.util.Collection<java.io.File> createThumbnailsAsCollection(java.util.Collection<? extends java.io.File> files, Rename rename, int width, int height) throws java.io.IOExceptionCreates thumbnails from a specifiedCollectionofFiles. The filenames of the resulting thumbnails are determined by applying the specifiedRename.The order of the thumbnail
Files in the returnedCollectionwill be the same as the order as the source list.- Parameters:
files- ACollectioncontainingFileobjects of image files.rename- The renaming function to use.width- The width of the thumbnail.height- The height of the thumbnail.- Returns:
- A collection of
Files to the thumbnails. - Throws:
java.io.IOException- Thrown when a problem occurs when reading fromFilerepresenting an image file.
-
createThumbnails
public static void createThumbnails(java.util.Collection<? extends java.io.File> files, Rename rename, int width, int height) throws java.io.IOExceptionCreates thumbnails from a specifiedCollectionofFiles. The filenames of the resulting thumbnails are determined by applying the specifiedRenamefunction.- Parameters:
files- ACollectioncontainingFileobjects of image files.rename- The renaming function to use.width- The width of the thumbnail.height- The height of the thumbnail.- Throws:
java.io.IOException- Thrown when a problem occurs when reading fromFilerepresenting an image file.
-
validateDimensions
private static void validateDimensions(int width, int height)Performs validation on the specified dimensions.If any of the dimensions are less than or equal to 0, an
IllegalArgumentExceptionis thrown with an message specifying the reason for the exception.This method is used to perform a check on the output dimensions of a thumbnail for the
createThumbnail(net.coobird.thumbnailator.tasks.ThumbnailTask<?, ?>)methods.- Parameters:
width- The width to validate.height- The height to validate.
-
-