Class Canvas
- java.lang.Object
-
- net.coobird.thumbnailator.filters.Canvas
-
- All Implemented Interfaces:
ImageFilter
public class Canvas extends java.lang.Object implements ImageFilter
AnImageFilterwhich will enclose an image into a specified enclosing image.The intended use of this
ImageFilteris to take an image and place it inside of a larger image, creating a border around the original image. This can be useful when the dimensions of a thumbnail must always be the same dimensions, and the original images are of differing dimensions.The fill color used for the enclosing image can be specified, along with whether or not to crop an image if it is larger than the enclosing image.
- Since:
- 0.3.2
-
-
Field Summary
Fields Modifier and Type Field Description private booleancropWhether or not to crop the enclosed image if the enclosing image is smaller than the enclosed image.private java.awt.ColorfillColorThe fill color for the background.private intheightThe width of the enclosing image.private PositionpositionThe positioning of the enclosed image.private intwidthThe width of the enclosing image.
-
Constructor Summary
Constructors Constructor Description Canvas(int width, int height, Position position)Instantiates aCanvasfilter.Canvas(int width, int height, Position position, boolean crop)Instantiates aCanvasfilter.Canvas(int width, int height, Position position, boolean crop, java.awt.Color fillColor)Instantiates aCanvasfilter.Canvas(int width, int height, Position position, java.awt.Color fillColor)Instantiates aCanvasfilter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.image.BufferedImageapply(java.awt.image.BufferedImage img)Applies a image filtering operation on an image.
-
-
-
Field Detail
-
width
private final int width
The width of the enclosing image.
-
height
private final int height
The width of the enclosing image.
-
position
private final Position position
The positioning of the enclosed image.
-
fillColor
private final java.awt.Color fillColor
The fill color for the background.
-
crop
private final boolean crop
Whether or not to crop the enclosed image if the enclosing image is smaller than the enclosed image.
-
-
Constructor Detail
-
Canvas
public Canvas(int width, int height, Position position)Instantiates aCanvasfilter.No fill color will be applied to the filtered image. If the image to filter does not have a transparency channel, the image will be filled black.
Crops the enclosed image if the enclosing image is smaller.
- Parameters:
width- The width of the filtered image.height- The height of the filtered image.position- The position to place the enclosed image.
-
Canvas
public Canvas(int width, int height, Position position, boolean crop)Instantiates aCanvasfilter.No fill color will be applied to the filtered image. If the image to filter does not have a transparency channel, the image will be filled black.
- Parameters:
width- The width of the filtered image.height- The height of the filtered image.position- The position to place the enclosed image.crop- Whether or not to crop the enclosed image if the enclosed image has dimensions which are larger than the specifiedwidthandheight.
-
Canvas
public Canvas(int width, int height, Position position, java.awt.Color fillColor)Instantiates aCanvasfilter.Crops the enclosed image if the enclosing image is smaller.
- Parameters:
width- The width of the filtered image.height- The height of the filtered image.position- The position to place the enclosed image.fillColor- The color to fill portions of the image which is not covered by the enclosed image. Portions of the image which is transparent will be filled with the specified color as well.
-
Canvas
public Canvas(int width, int height, Position position, boolean crop, java.awt.Color fillColor)Instantiates aCanvasfilter.- Parameters:
width- The width of the filtered image.height- The height of the filtered image.position- The position to place the enclosed image.crop- Whether or not to crop the enclosed image if the enclosed image has dimensions which are larger than the specifiedwidthandheight.fillColor- The color to fill portions of the image which is not covered by the enclosed image. Portions of the image which is transparent will be filled with the specified color as well.
-
-
Method Detail
-
apply
public java.awt.image.BufferedImage apply(java.awt.image.BufferedImage img)
Description copied from interface:ImageFilterApplies a image filtering operation on an image.- Specified by:
applyin interfaceImageFilter- Parameters:
img- The image to apply the filtering on.- Returns:
- The resulting image after applying this filter.
-
-