|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.loader.CmsImageScaler
Creates scaled images, acting as it's own parameter container.
Field Summary | |
static java.lang.String |
COLOR_TRANSPARENT
The name of the transparent color (for the backgound image). |
static java.lang.String |
FILTER_GRAYSCALE
The name of the grayscale image filter. |
static java.lang.String |
FILTER_SHADOW
The name of the shadow image filter. |
static java.util.List |
FILTERS
The supported image filter names. |
protected static org.apache.commons.logging.Log |
LOG
The log object for this class. |
static java.lang.String |
PARAM_SCALE
The (optional) parameter used for sending the scale information of an image in the http request. |
static int |
SCALE_DEFAULT_MAX_BLUR_SIZE
The default maximum image size (width * height) to apply image blurring when downscaling (setting this to high may case "out of memory" errors). |
static int |
SCALE_DEFAULT_MAX_SIZE
The default maximum image size (width or height) to allow when updowscaling an image using request parameters. |
static java.lang.String |
SCALE_PARAM_COLOR
The scaler parameter to indicate the requested image background color (if required). |
static java.lang.String |
SCALE_PARAM_FILTER
The scaler parameter to indicate the requested image filter. |
static java.lang.String |
SCALE_PARAM_HEIGHT
The scaler parameter to indicate the requested image height. |
static java.lang.String |
SCALE_PARAM_POS
The scaler parameter to indicate the requested image position (if required). |
static java.lang.String |
SCALE_PARAM_QUALITY
The scaler parameter to indicate to requested image save quality in percent (if applicable, for example used with JPEG images). |
static java.lang.String |
SCALE_PARAM_RENDERMODE
The scaler parameter to indicate to requested settings. |
static java.lang.String |
SCALE_PARAM_TYPE
The scaler parameter to indicate the requested scale type. |
static java.lang.String |
SCALE_PARAM_WIDTH
The scaler parameter to indicate the requested image width. |
Constructor Summary | |
|
CmsImageScaler()
Creates a new, empty image scaler object. |
|
CmsImageScaler(byte[] content,
java.lang.String rootPath)
Creates a new image scaler for the given image contained in the byte array. |
|
CmsImageScaler(CmsImageScaler original,
CmsImageScaler target)
Deprecated. use getReScaler(CmsImageScaler) on the original scaler instead |
protected |
CmsImageScaler(CmsImageScaler base,
int width,
int height)
Creates a new image scaler based on the given base scaler and the given width and height. |
|
CmsImageScaler(CmsObject cms,
CmsResource res)
Creates a new image scaler by reading the property
from the given resource. |
|
CmsImageScaler(javax.servlet.http.HttpServletRequest request,
int maxScaleSize,
int maxBlurSize)
Creates a new image scaler based on the given http request. |
|
CmsImageScaler(java.lang.String parameters)
Creates a new image scaler based on the given parameter String. |
Method Summary | |
void |
addFilter(java.lang.String filter)
Adds a filter name to the list of filters that should be applied to the image. |
java.lang.Object |
clone()
|
java.awt.Color |
getColor()
Returns the color. |
java.lang.String |
getColorString()
Returns the color as a String. |
CmsImageScaler |
getDownScaler(CmsImageScaler downScaler)
Returns a new image scaler that is a downscale from the size of this scaler
to the given scaler size. |
java.util.List |
getFilters()
Returns the list of image filter names (Strings) to be applied to the image. |
java.lang.String |
getFiltersString()
Returns the list of image filter names (Strings) to be applied to the image as a String. |
int |
getHeight()
Returns the height. |
java.lang.String |
getImageType(java.lang.String filename)
Returns the image type from the given file name based on the file suffix (extension) and the available image writers. |
int |
getMaxBlurSize()
Returns the maximum image size (width * height) to apply image blurring when downscaling images. |
int |
getPixelCount()
Returns the image pixel count, that is the image with multiplied by the image height. |
int |
getPosition()
Returns the position. |
int |
getQuality()
Returns the image saving quality in percent (0 - 100). |
int |
getRenderMode()
Returns the image rendering mode constant. |
CmsImageScaler |
getReScaler(CmsImageScaler target)
Returns a new image scaler that is a rescaler from the this scaler
size to the given target scaler size. |
int |
getType()
Returns the type. |
int |
getWidth()
Returns the width. |
CmsImageScaler |
getWidthScaler(CmsImageScaler downScaler)
Returns a new image scaler that is a width based downscale from the size of this scaler
to the given scaler size. |
int |
hashCode()
|
boolean |
isDownScaleRequired(CmsImageScaler downScaler)
Returns true if this image scaler must be downscaled when compared to the
given "downscale" image scaler. |
boolean |
isValid()
Returns true if all required parameters are available. |
void |
parseParameters(java.lang.String parameters)
Parses the given parameters and sets the internal scaler variables accordingly. |
byte[] |
scaleImage(byte[] content,
java.lang.String rootPath)
Returns a scaled version of the given image byte content according this image scalers parameters. |
byte[] |
scaleImage(CmsFile file)
Returns a scaled version of the given image file according this image scalers parameters. |
void |
setColor(java.awt.Color color)
Sets the color. |
void |
setColor(java.lang.String value)
Sets the color as a String. |
void |
setFilters(java.lang.String value)
Sets the list of filters as a String. |
void |
setHeight(int height)
Sets the height. |
void |
setMaxBlurSize(int maxBlurSize)
Sets the maximum image size (width * height) to apply image blurring when downscaling images. |
void |
setPosition(int position)
Sets the scale position. |
void |
setQuality(int quality)
Sets the image saving quality in percent. |
void |
setRenderMode(int renderMode)
Sets the image rendering mode constant. |
void |
setType(int type)
Sets the scale type. |
void |
setWidth(int width)
Sets the width. |
java.lang.String |
toRequestParam()
Creates a request parameter configured with the values from this image scaler, also appends a '?' |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String COLOR_TRANSPARENT
public static final java.lang.String FILTER_GRAYSCALE
public static final java.lang.String FILTER_SHADOW
public static final java.util.List FILTERS
public static final java.lang.String PARAM_SCALE
public static final int SCALE_DEFAULT_MAX_BLUR_SIZE
public static final int SCALE_DEFAULT_MAX_SIZE
public static final java.lang.String SCALE_PARAM_COLOR
public static final java.lang.String SCALE_PARAM_FILTER
public static final java.lang.String SCALE_PARAM_HEIGHT
public static final java.lang.String SCALE_PARAM_POS
public static final java.lang.String SCALE_PARAM_QUALITY
public static final java.lang.String SCALE_PARAM_RENDERMODE
RenderingHints
settings.
public static final java.lang.String SCALE_PARAM_TYPE
public static final java.lang.String SCALE_PARAM_WIDTH
protected static final org.apache.commons.logging.Log LOG
Constructor Detail |
public CmsImageScaler()
public CmsImageScaler(byte[] content, java.lang.String rootPath)
Please note:The image itself is not stored in the scaler, only the width and
height dimensions of the image. To actually scale an image, you need to use
. This constructor is commonly used only
to extract the image dimensions, for example when creating a String value for
the scaleImage(CmsFile)
property.CmsPropertyDefinition.PROPERTY_IMAGE_SIZE
In case the byte array can not be decoded to an image, or in case of other errors,
will return isValid()
false
.
content
- the image to calculate the dimensions forrootPath
- the root path of the resource (for error logging)public CmsImageScaler(CmsImageScaler original, CmsImageScaler target)
getReScaler(CmsImageScaler)
on the original
scaler instead
original
- the scaler that holds the original image dimensionstarget
- the image scaler to be used for rescaling this image scalerpublic CmsImageScaler(CmsObject cms, CmsResource res)
CmsPropertyDefinition.PROPERTY_IMAGE_SIZE
from the given resource.
In case of any errors reading or parsing the property,
will return isValid()
false
.
cms
- the OpenCms user context to use when reading the propertyres
- the resource to read the property frompublic CmsImageScaler(javax.servlet.http.HttpServletRequest request, int maxScaleSize, int maxBlurSize)
request
- the http request to read the parameters frommaxScaleSize
- the maximum scale size (width or height) for the imagemaxBlurSize
- the maximum size of the image (width * height) to apply blur (may cause "out of memory" for large images)public CmsImageScaler(java.lang.String parameters)
parameters
- the scale parameters to useprotected CmsImageScaler(CmsImageScaler base, int width, int height)
base
- the base scaler to initialize the values withwidth
- the width to set for this scalerheight
- the height to set for this scalerMethod Detail |
public void addFilter(java.lang.String filter)
filter
- the filter name to addpublic java.lang.Object clone()
Object.clone()
public java.awt.Color getColor()
public java.lang.String getColorString()
public CmsImageScaler getDownScaler(CmsImageScaler downScaler)
this
scaler
to the given scaler size.
If no downscale from this to the given scaler is required according to
isDownScaleRequired(CmsImageScaler)
, then null
is returned.
downScaler
- the image scaler that holds the downscaled target image dimensions
this
scaler
to the given target scaler size, or null
public java.util.List getFilters()
public java.lang.String getFiltersString()
public int getHeight()
public java.lang.String getImageType(java.lang.String filename)
For example, for the file name "opencms.gif" the type is GIF, for "opencms.jpg" is is "JPEG" etc.
In case the input filename has no suffix, or there is no known image writer for the format defined
by the suffix, null
is returned.
Any non-null result can be used if an image type input value is required.
filename
- the file name to get the type for
public int getMaxBlurSize()
Image blurring is required to achive the best results for downscale operatios when the target image size is 2 times or more smaller then the original image size. This parameter controls the maximum size (width * height) of an image that is blurred before it is downscaled. If the image is larger, no blurring is done. However, image blurring is an expensive operation in both CPU usage and memory consumption. Setting the blur size to large may case "out of memory" errors.
public int getPixelCount()
If this scalier is not valid (see isValid()
) the result is undefined.
public int getPosition()
public int getQuality()
This is used oly if applicable, for example when saving JPEG images.
public int getRenderMode()
Possible values are:
Simapi.RENDER_QUALITY
(default)Simapi.RENDER_SPEED
Simapi.RENDER_MEDIUM
Simapi.RENDER_QUALITY
mode.
public CmsImageScaler getReScaler(CmsImageScaler target)
this
scaler
size to the given target scaler size.The height of the target image is calculated in proportion to the original image width. If the width of the the original image is not known, the target image width is calculated in proportion to the original image height.
target
- the image scaler that holds the target image dimensions
this
scaler
size to the given target scaler size.public int getType()
Possible values are:
public int getWidth()
public CmsImageScaler getWidthScaler(CmsImageScaler downScaler)
this
scaler
to the given scaler size.
If no downscale from this to the given scaler is required because the width of this
scaler is not larger than the target width, then the image dimensions of this
scaler
are unchanged in the result scaler. No upscaling is done!
downScaler
- the image scaler that holds the downscaled target image dimensions
this
scaler
to the given target scaler sizepublic int hashCode()
Object.hashCode()
public boolean isDownScaleRequired(CmsImageScaler downScaler)
true
if this image scaler must be downscaled when compared to the
given "downscale" image scaler.
If either this
scaler or the given downScaler
is invalid according to
isValid()
, then false
is returned.
The use case: this
scaler represents an image (that is contains width and height of
an image). The downScaler
represents the maximum wanted image. The scalers
are compared and if the image represented by this
scaler is too large,
true
is returned. Image orientation is ignored, so for example an image with 600x800 pixel
will NOT be downscaled if the target size is 800x600 but kept unchanged.
downScaler
- the downscaler to compare this image scaler with
true
if this image scaler must be downscaled when compared to the
given "downscale" image scalerpublic boolean isValid()
true
if all required parameters are available.Required parameters are "h" (height), and "w" (width).
true
if all required parameters are availablepublic void parseParameters(java.lang.String parameters)
The parameter String must have the format "h:100,w:200,t:1"
,
that is a comma separated list of attributes followed by a colon ":", followed by a value.
As possible attributes, use the constants from this class that start with SCALE_PARAM
for example SCALE_PARAM_HEIGHT
or SCALE_PARAM_WIDTH
.
parameters
- the parameters to parsepublic byte[] scaleImage(byte[] content, java.lang.String rootPath)
content
- the image byte content to scalerootPath
- the root path of the image file in the VFS
public byte[] scaleImage(CmsFile file)
file
- the image file to scale
public void setColor(java.awt.Color color)
color
- the color to setpublic void setColor(java.lang.String value)
value
- the color to setpublic void setFilters(java.lang.String value)
value
- the list of filters to setpublic void setHeight(int height)
height
- the height to setpublic void setMaxBlurSize(int maxBlurSize)
maxBlurSize
- the maximum image blur size to setfor a more detailed description about this parameter
public void setPosition(int position)
position
- the position to setpublic void setQuality(int quality)
quality
- the image saving quality (in percent) to setpublic void setRenderMode(int renderMode)
renderMode
- the image rendering mode to setfor a list of allowed values for the rendering mode
public void setType(int type)
type
- the scale type to setfor a detailed description of the possible values for the type
public void setWidth(int width)
width
- the width to setpublic java.lang.String toRequestParam()
'?'
char as a prefix so that this may be direclty appended to an image URL.This can be appended to an image request in order to apply image scaling parameters.
public java.lang.String toString()
Object.toString()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |