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 and Description |
---|
ScaleImageOperation(int width,
int height,
boolean upscaling)
Deprecated.
Use
ScalingParameters.Builder instead. |
ScaleImageOperation(int width,
int height,
boolean upscaling,
boolean cropping,
ImageUtils.ScalingStrategy strategy,
float compressionQuality)
Deprecated.
Use
ScalingParameters.Builder instead. |
ScaleImageOperation(int width,
int height,
boolean upscaling,
ImageUtils.ScalingStrategy strategy)
Deprecated.
Use
ScalingParameters.Builder instead. |
ScaleImageOperation(int width,
int height,
boolean upscaling,
ImageUtils.ScalingStrategy strategy,
float compressionQuality)
Deprecated.
Use
ScalingParameters.Builder instead. |
ScaleImageOperation(ScalingParameters parameters)
Creates a scaling operation from a complete set of scaling parameters.
|
Modifier and Type | Method and 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.
|
calculateResizeRatio, calculateResizeRatio, getCompressionQuality, getParameters, getScaledData, getScaledHeight, getScaledWidth
execute, getResult, setResult
public ScaleImageOperation(ScalingParameters parameters)
parameters
- the parameters to use for the scaling@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling)
ScalingParameters.Builder
instead.ImageUtils.ScalingStrategy.QUALITY
, and the
maximum memory usage to zero (i.e. undefined).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@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy)
ScalingParameters.Builder
instead.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.)@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy, float compressionQuality)
ScalingParameters.Builder
instead.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.@Deprecated public ScaleImageOperation(int width, int height, boolean upscaling, boolean cropping, ImageUtils.ScalingStrategy strategy, float compressionQuality)
ScalingParameters.Builder
instead.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.public ImageOperationResult run(InputStream data, String mimeType) throws GalleryException
ImageOperation
run
in interface ImageOperation
run
in class AbstractImageOperation
data
- the image data. The stream is closed by this method.mimeType
- MIME type of the imageGalleryException
- when the image operation failspublic void execute(InputStream data, ImageReader reader, ImageWriter writer) throws IOException
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.
execute
in class AbstractImageOperation
data
- the original image datareader
- reader for the image datawriter
- writer for the image dataIOException
- when the image operation failsprotected BufferedImage processImage(ImageReader reader, int originalWidth, int originalHeight) throws IOException
IOException
Copyright © 2007–2019 Hippo B.V. (http://www.onehippo.com). All rights reserved.