public class ScaleImageOperation extends AbstractImageOperation
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.
Constructor and Description |
---|
ScaleImageOperation(int width,
int height,
boolean upscaling)
Creates a image scaling operation, defined by the bounding box of a certain width and height.
|
ScaleImageOperation(int width,
int height,
boolean upscaling,
ImageUtils.ScalingStrategy strategy)
Creates a image scaling operation, defined by the bounding box of a certain width and height.
|
ScaleImageOperation(int width,
int height,
boolean upscaling,
ImageUtils.ScalingStrategy strategy,
float compressionQuality)
Creates a image scaling operation, defined by the bounding box of a certain width and height.
|
Modifier and Type | Method and Description |
---|---|
protected double |
calculateResizeRatio(double originalWidth,
double originalHeight,
int targetWidth,
int targetHeight) |
void |
execute(InputStream data,
ImageReader reader,
ImageWriter writer)
Creates a scaled version of an image.
|
void |
execute(InputStream data,
String mimeType)
Executes an image operation.
|
float |
getCompressionQuality() |
InputStream |
getScaledData() |
int |
getScaledHeight() |
int |
getScaledWidth() |
public ScaleImageOperation(int width, int height, boolean upscaling)
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 boxpublic ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy)
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.)public ScaleImageOperation(int width, int height, boolean upscaling, ImageUtils.ScalingStrategy strategy, float compressionQuality)
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.public void execute(InputStream data, String mimeType) throws GalleryException
AbstractImageOperation
execute
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 double calculateResizeRatio(double originalWidth, double originalHeight, int targetWidth, int targetHeight)
public InputStream getScaledData()
public int getScaledWidth()
public int getScaledHeight()
public float getCompressionQuality()
Copyright © 2007–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.