Package com.twelvemonkeys.servlet.image
Class ScaleFilter
- java.lang.Object
-
- com.twelvemonkeys.servlet.GenericFilter
-
- com.twelvemonkeys.servlet.image.ImageFilter
-
- com.twelvemonkeys.servlet.image.ScaleFilter
-
- All Implemented Interfaces:
java.io.Serializable
,javax.servlet.Filter
,javax.servlet.FilterConfig
- Direct Known Subclasses:
CropFilter
public class ScaleFilter extends ImageFilter
This filter renders a scaled version of an image read from a given URL. The image can be output as a GIF, JPEG or PNG image or similar.
scaleX
- integer, the new width of the image.
scaleY
- integer, the new height of the image.
scaleUniform
- boolean, wether or not uniform scalnig should be used. Default is
true
. scaleUnits
- string, one of
PIXELS
,PERCENT
.PIXELS
is default. scaleQuality
- string, one of
SCALE_SMOOTH
,SCALE_FAST
,SCALE_REPLICATE
,SCALE_AREA_AVERAGING
.SCALE_DEFAULT
is default (seeImage.getScaledInstance(int,int,int)
,Image
for more details).
Examples:
<IMG src="/scale/test.jpg?scaleX=500&scaleUniform=false"> <IMG src="/scale/test.png?scaleY=50&scaleUnits=PERCENT">
- Version:
- $Id: ScaleFilter.java#1 $
- Author:
- Harald Kuhr, last modified by $Author: haku $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
defaultScaleQuality
protected static java.lang.String
PARAM_IMAGE
image
protected static java.lang.String
PARAM_SCALE_QUALITY
scaleQuality
protected static java.lang.String
PARAM_SCALE_UNIFORM
scaleUniform
protected static java.lang.String
PARAM_SCALE_UNITS
scaleUnits
protected static java.lang.String
PARAM_SCALE_X
scaleX
protected static java.lang.String
PARAM_SCALE_Y
scaleY
static int
UNITS_PERCENT
Width and height are percentage of original width and height.static int
UNITS_PIXELS
Width and height are absolute pixels.static int
UNITS_UNKNOWN
Unknown units.-
Fields inherited from class com.twelvemonkeys.servlet.image.ImageFilter
triggerParams
-
Fields inherited from class com.twelvemonkeys.servlet.GenericFilter
oncePerRequest
-
-
Constructor Summary
Constructors Constructor Description ScaleFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.awt.image.RenderedImage
doFilter(java.awt.image.BufferedImage pImage, javax.servlet.ServletRequest pRequest, ImageServletResponse pResponse)
Reads the image from the requested URL, scales it, and returns it in the Servlet stream.protected java.awt.Dimension
getDimensions(java.awt.Image pImage, int pWidth, int pHeight, int pUnits, boolean pUniformScale)
Gets the dimensions (height and width) of the scaled image.protected int
getQuality(java.lang.String pQualityStr)
Gets the quality constant for the scaling, from the string argument.protected int
getUnits(java.lang.String pUnitStr)
Gets the units constant for the width and height arguments, from the given string argument.void
setDefaultScaleQuality(java.lang.String pDefaultScaleQuality)
-
Methods inherited from class com.twelvemonkeys.servlet.image.ImageFilter
doFilterImpl, setTriggerParams, trigger
-
Methods inherited from class com.twelvemonkeys.servlet.GenericFilter
destroy, doFilter, getFilterConfig, getFilterName, getInitParameter, getInitParameterNames, getServletContext, init, init, log, log, setFilterConfig, setOncePerRequest
-
-
-
-
Field Detail
-
UNITS_PIXELS
public static final int UNITS_PIXELS
Width and height are absolute pixels. The default.- See Also:
- Constant Field Values
-
UNITS_PERCENT
public static final int UNITS_PERCENT
Width and height are percentage of original width and height.- See Also:
- Constant Field Values
-
UNITS_UNKNOWN
public static final int UNITS_UNKNOWN
Unknown units.- See Also:
- Constant Field Values
-
PARAM_SCALE_QUALITY
protected static final java.lang.String PARAM_SCALE_QUALITY
scaleQuality
- See Also:
- Constant Field Values
-
PARAM_SCALE_UNITS
protected static final java.lang.String PARAM_SCALE_UNITS
scaleUnits
- See Also:
- Constant Field Values
-
PARAM_SCALE_UNIFORM
protected static final java.lang.String PARAM_SCALE_UNIFORM
scaleUniform
- See Also:
- Constant Field Values
-
PARAM_SCALE_X
protected static final java.lang.String PARAM_SCALE_X
scaleX
- See Also:
- Constant Field Values
-
PARAM_SCALE_Y
protected static final java.lang.String PARAM_SCALE_Y
scaleY
- See Also:
- Constant Field Values
-
PARAM_IMAGE
protected static final java.lang.String PARAM_IMAGE
image
- See Also:
- Constant Field Values
-
defaultScaleQuality
protected int defaultScaleQuality
-
-
Method Detail
-
doFilter
protected java.awt.image.RenderedImage doFilter(java.awt.image.BufferedImage pImage, javax.servlet.ServletRequest pRequest, ImageServletResponse pResponse)
Reads the image from the requested URL, scales it, and returns it in the Servlet stream. See above for details on parameters.- Specified by:
doFilter
in classImageFilter
- Parameters:
pImage
- the image to filterpRequest
- the servlet requestpResponse
- the servlet response- Returns:
- the filtered image
-
getQuality
protected int getQuality(java.lang.String pQualityStr)
Gets the quality constant for the scaling, from the string argument.- Parameters:
pQualityStr
- The string representation of the scale quality constant.- Returns:
- The matching quality constant, or the default quality if none was found.
- See Also:
Image
,Image.getScaledInstance(int,int,int)
-
setDefaultScaleQuality
public void setDefaultScaleQuality(java.lang.String pDefaultScaleQuality)
-
getUnits
protected int getUnits(java.lang.String pUnitStr)
Gets the units constant for the width and height arguments, from the given string argument.- Parameters:
pUnitStr
- The string representation of the units constant, can be one of "PIXELS" or "PERCENT".- Returns:
- The mathcing units constant, or UNITS_UNKNOWN if none was found.
-
getDimensions
protected java.awt.Dimension getDimensions(java.awt.Image pImage, int pWidth, int pHeight, int pUnits, boolean pUniformScale)
Gets the dimensions (height and width) of the scaled image. The dimensions are computed based on the old image's dimensions, the units used for specifying new dimensions and whether or not uniform scaling should be used (se algorithm below).- Parameters:
pImage
- the image to be scaledpWidth
- the new width of the image, or -1 if unknownpHeight
- the new height of the image, or -1 if unknownpUnits
- the constant specifying units for width and height parameter (UNITS_PIXELS or UNITS_PERCENT)pUniformScale
- boolean specifying uniform scale or not- Returns:
- a Dimension object, with the correct width and heigth in pixels, for the scaled version of the image.
-
-