Class ScaleImageOperation
- java.lang.Object
-
- org.hippoecm.frontend.plugins.gallery.imageutil.AbstractImageOperation
-
- org.hippoecm.frontend.plugins.gallery.imageutil.AbstractScaleImageOperation
-
- org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperation
-
- All Implemented Interfaces:
ImageOperation
- Direct Known Subclasses:
CropAndScaleImageOperation
public class ScaleImageOperation extends AbstractScaleImageOperation
Creates a scaled version of an image. The given scaling parameters define a bounding box with a certain width and height. Images that do not fit in this box (i.e. are too large) are always scaled down such that they do fit. If the aspect ratio of the original image differs from that of the bounding box, either the width or the height of scaled image will be less than that of the box.
Unless of course cropping is set to true, then the original images is cropped to fill the bounding box.
Smaller images are scaled up in the same way as large images are scaled down, but only if upscaling is true. When upscaling is false and the image is smaller than the bounding box, the scaled image will be equal to the original.
If the width or height of the scaling parameters is 0 or less, that side of the bounding box does not exist (i.e. is unbounded). If both sides of the bounding box are unbounded, the scaled image will be equal to the original.
-
-
Constructor Summary
Constructors Constructor Description ScaleImageOperation(int width, int height, boolean upscaling)
Deprecated.UseScalingParameters.Builder
instead.ScaleImageOperation(int width, int height, boolean upscaling, boolean cropping, ImageUtils.ScalingStrategy strategy, float compressionQuality)
Deprecated.UseScalingParameters.Builder
instead.ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy)
Deprecated.UseScalingParameters.Builder
instead.ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy, float compressionQuality)
Deprecated.UseScalingParameters.Builder
instead.ScaleImageOperation(ScalingParameters parameters)
Creates a scaling operation from a complete set of scaling parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(InputStream data, ImageReader reader, ImageWriter writer)
Creates a scaled version of an image.protected BufferedImage
processImage(ImageReader reader, int originalWidth, int originalHeight)
ImageOperationResult
run(InputStream data, String mimeType)
Runs an image operation and returns the result.-
Methods inherited from class org.hippoecm.frontend.plugins.gallery.imageutil.AbstractScaleImageOperation
calculateResizeRatio, calculateResizeRatio, getCompressionQuality, getParameters, getScaledData, getScaledHeight, getScaledWidth
-
Methods inherited from class org.hippoecm.frontend.plugins.gallery.imageutil.AbstractImageOperation
execute, getResult, setResult
-
-
-
-
Constructor Detail
-
ScaleImageOperation
public ScaleImageOperation(ScalingParameters parameters)
Creates a scaling operation from a complete set of scaling parameters.- Parameters:
parameters
- the parameters to use for the scaling
-
ScaleImageOperation
@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling)
Deprecated.UseScalingParameters.Builder
instead.Creates a image scaling operation, defined by the bounding box of a certain width and height. The strategy will be set toImageUtils.ScalingStrategy.QUALITY
, and the maximum memory usage to zero (i.e. undefined).- Parameters:
width
- the width of the bounding box in pixelsheight
- the height of the bounding box in pixelsupscaling
- whether to enlarge images that are smaller than the bounding box
-
ScaleImageOperation
@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy)
Deprecated.UseScalingParameters.Builder
instead.Creates a image scaling operation, defined by the bounding box of a certain width and height.- Parameters:
width
- the width of the bounding box in pixelsheight
- the height of the bounding box in pixelsupscaling
- whether to enlarge images that are smaller than the bounding boxstrategy
- the strategy to use for scaling the image (e.g. optimize for speed, quality, a trade-off between these two, etc.)
-
ScaleImageOperation
@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy, float compressionQuality)
Deprecated.UseScalingParameters.Builder
instead.Creates a image scaling operation, defined by the bounding box of a certain width and height.- Parameters:
width
- the width of the bounding box in pixelsheight
- the height of the bounding box in pixelsupscaling
- whether to enlarge images that are smaller than the bounding boxstrategy
- the strategy to use for scaling the image (e.g. optimize for speed, quality, a trade-off between these two, etc.)compressionQuality
- a float between 0 and 1 indicating the compression quality to use for writing the scaled image data.
-
ScaleImageOperation
@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling, boolean cropping, ImageUtils.ScalingStrategy strategy, float compressionQuality)
Deprecated.UseScalingParameters.Builder
instead.Creates a image scaling operation, defined by the bounding box of a certain width and height.- Parameters:
width
- the width of the bounding box in pixelsheight
- the height of the bounding box in pixelsupscaling
- whether to enlarge images that are smaller than the bounding boxcropping
- whether to crop to original to fill the bounding boxstrategy
- the strategy to use for scaling the image (e.g. optimize for speed, quality, a trade-off between these two, etc.)compressionQuality
- a float between 0 and 1 indicating the compression quality to use for writing the scaled image data.
-
-
Method Detail
-
run
public ImageOperationResult run(InputStream data, String mimeType) throws GalleryException
Description copied from interface:ImageOperation
Runs an image operation and returns the result.- Specified by:
run
in interfaceImageOperation
- Overrides:
run
in classAbstractImageOperation
- Parameters:
data
- the image data. The stream is closed by this method.mimeType
- MIME type of the image- Throws:
GalleryException
- when the image operation fails
-
execute
public void execute(InputStream data, ImageReader reader, ImageWriter writer) throws IOException
Creates a scaled version of an image. The given scaling parameters define a bounding box with a certain width and height. Images that do not fit in this box (i.e. are too large) are always scaled down such that they do fit. If the aspect ratio of the original image differs from that of the bounding box, either the width or the height of scaled image will be less than that of the box.Smaller images are scaled up in the same way as large images are scaled down, but only if upscaling is true. When upscaling is false and the image is smaller than the bounding box, the scaled image will be equal to the original.
If the width or height of the scaling parameters is 0 or less, that side of the bounding box does not exist (i.e. is unbounded). If both sides of the bounding box are unbounded, the scaled image will be equal to the original.
- Specified by:
execute
in classAbstractImageOperation
- Parameters:
data
- the original image datareader
- reader for the image datawriter
- writer for the image data- Throws:
IOException
- when the image operation fails
-
processImage
protected BufferedImage processImage(ImageReader reader, int originalWidth, int originalHeight) throws IOException
- Throws:
IOException
-
-