Package de.xima.fc.common.image
Class CropScaleImageThumbnailGenerator
- java.lang.Object
-
- de.xima.fc.common.image.CropScaleImageThumbnailGenerator
-
- All Implemented Interfaces:
IImageThumbnailGenerator
,Serializable
public final class CropScaleImageThumbnailGenerator extends Object implements IImageThumbnailGenerator
A thumbnail generator that scales down images to a defined width and height. Scales (down) images so to the configured size. The aspect ratio is preserved. Images with an aspect ratio that does not match the requested width and height are cropped appropriately, so that the generated thumbnails always have the exact configured width and height.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CropScaleImageThumbnailGenerator.Builder
A builder for a thumbnail generator that scales down images to a defined width and height.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CropScaleImageThumbnailGenerator.Builder
builder()
Gets a builder for a thumbnail generator that scales down images to a defined width and height.TypedByteArray
generateThumbnail(byte[] data, ImageThumbnailGeneratorConstraints constraints)
Generate a thumbnail for the given image data.TypedFile
generateThumbnail(String fileName, InputStream sourceImage, Path outputLocation, ImageThumbnailGeneratorConstraints constraints)
Generate a thumbnail for the given image file, and stores it at the specified output location.TypedFile
generateThumbnail(Path sourceImage, Path outputLocation, ImageThumbnailGeneratorConstraints constraints)
Generate a thumbnail for the given image file, and stores it at the specified output location.
-
-
-
Method Detail
-
generateThumbnail
public TypedByteArray generateThumbnail(byte[] data, ImageThumbnailGeneratorConstraints constraints) throws IOException
Description copied from interface:IImageThumbnailGenerator
Generate a thumbnail for the given image data.- Specified by:
generateThumbnail
in interfaceIImageThumbnailGenerator
- Parameters:
data
- The image data.constraints
- Requested constraints on the thumbnail generation. May or may not be respected by the implementation. null if no constraints are specified.- Returns:
- The generated thumbnail, including its content type (MIME type).
- Throws:
IOException
- If the thumbnail could not be generated.
-
generateThumbnail
public TypedFile generateThumbnail(Path sourceImage, Path outputLocation, ImageThumbnailGeneratorConstraints constraints) throws IOException
Description copied from interface:IImageThumbnailGenerator
Generate a thumbnail for the given image file, and stores it at the specified output location. The output location may be either an existing directory, in which case a new file is created within that directory, or a file path. If the file exists, it is overwritten.- Specified by:
generateThumbnail
in interfaceIImageThumbnailGenerator
- Parameters:
sourceImage
- The image file for which to generate a thumbnail.outputLocation
- Where to store the thumbnail. Either an existing folder or a file path.constraints
- Requested constraints on the thumbnail generation. May or may not be respected by the implementation. null if no constraints are specified.- Returns:
- The generated thumbnail file.
- Throws:
IOException
- If the thumbnail could not be generated.
-
generateThumbnail
public TypedFile generateThumbnail(String fileName, InputStream sourceImage, Path outputLocation, ImageThumbnailGeneratorConstraints constraints) throws IOException
Description copied from interface:IImageThumbnailGenerator
Generate a thumbnail for the given image file, and stores it at the specified output location. The output location may be either an existing directory, in which case a new file is created within that directory, or a file path. If the file exists, it is overwritten.- Specified by:
generateThumbnail
in interfaceIImageThumbnailGenerator
- Parameters:
fileName
- The name of the image file for which to generate a thumbnail.sourceImage
- The data of the image file for which to generate a thumbnail.outputLocation
- Where to store the thumbnail. Either an existing folder or a file path.constraints
- Requested constraints on the thumbnail generation. May or may not be respected by the implementation. null if no constraints are specified.- Returns:
- The generated thumbnail file.
- Throws:
IOException
- If the thumbnail could not be generated.
-
builder
public static CropScaleImageThumbnailGenerator.Builder builder()
Gets a builder for a thumbnail generator that scales down images to a defined width and height. Images that do not fit the aspect ratio are cropped appropriately.- Returns:
- A builder for a thumbnail generator.
-
-