de.innovationgate.utils.imgscalr
public class ImgScalrScaler extends java.lang.Object implements ImageScaler, MimeTypeSpecificImageScaler
Modifier and Type | Field and Description |
---|---|
static java.util.List<java.lang.String> |
SUPPORTED_MIMETYPES |
static java.lang.String |
SYSPROPERTY_METHOD |
Constructor and Description |
---|
ImgScalrScaler() |
Modifier and Type | Method and Description |
---|---|
void |
crop(int x,
int y,
int width,
int height)
This method crops out the selected area from an image
The parameters x and y defines the start coordinate.
|
long |
determineRenderedSize()
Determines the bytes size of the image if it would be written to an output stream.
|
float |
getAspectRatio()
Returns the aspect ratio (width/height) of the image
|
java.lang.String |
getFormat()
Returns the output format.
|
java.lang.String |
getFormatSuffix()
Returns the normale file suffix for the current output format, including leading "."
|
int |
getHeight()
Returns the current image height
|
java.lang.Object |
getImageEncodeParam()
Returns the image encoding params.
|
float |
getQuality()
Returns the quality of the output format.
|
java.lang.String |
getSourceFileName()
Returns the name of the sourcefile
|
int |
getWidth()
Returns the current image width
|
void |
growToSize(int width,
int height)
Scales the images up to fit given minimum sizes.
|
boolean |
isTransparencySupportedForOutput()
Returns if transparency is supported by the current output format
|
void |
load(java.io.InputStream is)
Loads image data.
|
void |
load(java.io.InputStream is,
java.lang.String mimeType)
Loads image data.
|
void |
scaleByFactor(int hfactor,
int vfactor)
Scales the image based on the given scaling factors.
|
void |
scaleToSize(int width,
int height)
Scales the image to a determined target size
This method uses the parameter width and height as target sizes for the scaled image.
|
void |
scaleToSize(int width,
int height,
boolean keepRatio)
Scales the image to the determined target size
if keepRation==true
image orientation is determined (landscape or portrait)
on landscape the image is scaled with the same ratio to the given width
on portrait the image is scaled with the same ratio to the given height
|
void |
setFormat(java.lang.String format)
Sets the output format
|
void |
setImageEncodeParam(java.lang.Object imageEncodeParam)
Sets the image encoding params
|
void |
setQuality(float q)
Sets the quality of the output format.
|
void |
setSourceFileName(java.lang.String name)
Sets the name of the sourcefile
|
void |
shrinkToSize(int width,
int height)
Scales the images down to fit into given maximum sizes.
|
void |
useJPEGForOutput()
Sets the scaler to use JPEG images for output with 90% quality.
|
void |
usePNGForOutput()
Sets the scaler to use PNG images (with color palette) for output,
|
void |
writeImage(java.io.File outFile)
Writes the rendered and scaled image to a file.
|
void |
writeImage(java.io.OutputStream out)
Writes the rendered and scaled image to an outputstream
|
public static final java.lang.String SYSPROPERTY_METHOD
public static final java.util.List<java.lang.String> SUPPORTED_MIMETYPES
public void load(java.io.InputStream is) throws java.io.IOException
ImageScaler
load
in interface ImageScaler
is
- image data input stream.java.io.IOException
public void useJPEGForOutput()
ImageScaler
useJPEGForOutput
in interface ImageScaler
public void usePNGForOutput()
ImageScaler
usePNGForOutput
in interface ImageScaler
public void scaleToSize(int width, int height)
ImageScaler
scaleToSize
in interface ImageScaler
width
- The target width. Use -1 to automatically calculate target width for keeping the image ratioheight
- The target height. Use -1 to automatically calculate target height for keeping the image ratiopublic void scaleToSize(int width, int height, boolean keepRatio)
ImageScaler
scaleToSize
in interface ImageScaler
scaleToSize
in interface MimeTypeSpecificImageScaler
width
- The target widthheight
- The target heightkeepRatio
- true/ falsepublic float getAspectRatio()
public void scaleByFactor(int hfactor, int vfactor)
ImageScaler
scaleByFactor
in interface ImageScaler
scaleByFactor
in interface MimeTypeSpecificImageScaler
hfactor
- The horizontal scaling factorvfactor
- The vertical scaling factorpublic void shrinkToSize(int width, int height)
ImageScaler
shrinkToSize
in interface ImageScaler
shrinkToSize
in interface MimeTypeSpecificImageScaler
width
- The maximum widthheight
- The maximum heightpublic void growToSize(int width, int height)
ImageScaler
growToSize
in interface ImageScaler
growToSize
in interface MimeTypeSpecificImageScaler
width
- The maximum widthheight
- The maximum heightpublic void writeImage(java.io.OutputStream out)
ImageScaler
writeImage
in interface ImageScaler
writeImage
in interface MimeTypeSpecificImageScaler
public void writeImage(java.io.File outFile) throws java.io.IOException
ImageScaler
writeImage
in interface ImageScaler
java.io.IOException
- if the file cannot be writtenpublic java.lang.String getFormat()
ImageScaler
getFormat
in interface ImageScaler
public void setFormat(java.lang.String format)
ImageScaler
setFormat
in interface ImageScaler
format
- The format to set.public java.lang.Object getImageEncodeParam()
ImageScaler
getImageEncodeParam
in interface ImageScaler
getImageEncodeParam
in interface MimeTypeSpecificImageScaler
public void setImageEncodeParam(java.lang.Object imageEncodeParam)
ImageScaler
setImageEncodeParam
in interface ImageScaler
setImageEncodeParam
in interface MimeTypeSpecificImageScaler
imageEncodeParam
- The imageEncodeParam to set.public float getQuality()
ImageScaler
getQuality
in interface ImageScaler
public void setQuality(float q)
ImageScaler
setQuality
in interface ImageScaler
public int getWidth()
ImageScaler
getWidth
in interface ImageScaler
getWidth
in interface MimeTypeSpecificImageScaler
public int getHeight()
ImageScaler
getHeight
in interface ImageScaler
getHeight
in interface MimeTypeSpecificImageScaler
public long determineRenderedSize()
ImageScaler
determineRenderedSize
in interface ImageScaler
determineRenderedSize
in interface MimeTypeSpecificImageScaler
public boolean isTransparencySupportedForOutput()
ImageScaler
isTransparencySupportedForOutput
in interface ImageScaler
isTransparencySupportedForOutput
in interface MimeTypeSpecificImageScaler
public java.lang.String getFormatSuffix()
ImageScaler
getFormatSuffix
in interface ImageScaler
public java.lang.String getSourceFileName()
ImageScaler
getSourceFileName
in interface ImageScaler
public void setSourceFileName(java.lang.String name)
ImageScaler
setSourceFileName
in interface ImageScaler
public void load(java.io.InputStream is, java.lang.String mimeType) throws java.lang.IllegalArgumentException, java.io.IOException
MimeTypeSpecificImageScaler
load
in interface MimeTypeSpecificImageScaler
is
- image data input stream.mimeType
- of the loaded imagejava.lang.IllegalArgumentException
- if the mimetype is not supportedjava.io.IOException
- if something goes wrong on loadingpublic void crop(int x, int y, int width, int height) throws java.lang.UnsupportedOperationException, java.io.IOException
MimeTypeSpecificImageScaler
crop
in interface MimeTypeSpecificImageScaler
java.lang.UnsupportedOperationException
- If this scaler does not support croppingjava.io.IOException