Class SizedImageTag
- java.lang.Object
-
- javax.servlet.jsp.tagext.SimpleTagSupport
-
- nl.gx.webmanager.taglib.SizedImageTag
-
- All Implemented Interfaces:
javax.servlet.jsp.tagext.JspTag
,javax.servlet.jsp.tagext.SimpleTag
public class SizedImageTag extends javax.servlet.jsp.tagext.SimpleTagSupport
wm:sizedImage
tag resizes image objects.The target dimensions can be specified using the
width
andheight
attibutes. If only one ofwidth
orheight
are given, then the other will automatically be calculated to preserve the image's aspect ratio.There are two different possible methods used for scaling and cropping the image: CROP and SCALE.
CROP scales the image such that it completely covers the target dimensions. Any parts of the image that fall outside the target are cropped off. This mode generates a resulting image which has the exact same dimensions as the requested target dimensions.
SCALE scale the image such that it neatly fits completely inside the target dimensions. This mode can generate a result image with dimensions which are different (smaller) than the requested target dimensions.
Both modes preserve the image's aspect ratio and are set using the
mode
attribute. The default is CROP.The quality (or compression level) must be a value between 0 and 1. See
nl.gx.siteworks.util.ImageUtil.resizeAndCropToJPG
for more information.Example of usage:
< wm:image var="bullet" url=" http://www.gx.nl/images/bullet.jpg " /> < wm:sizedImage var="bulletSmall" image="${bullet}" width="20" height="20" quality="0.5" /> ${bulletSmall.htmlTag}
In the example above the image stored in the variable "bullet" is resized to 20x20 pixels with a quality (compression) of 0.5 and returned in the variable "bulletSmall".
-
-
Constructor Summary
Constructors Constructor Description SizedImageTag()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doTag()
void
setHeight(Integer height)
Sets the height of the resized image in pixels.void
setImage(Image image)
Specifies the image object to resize.void
setMode(String mode)
Set the mode.void
setProgressive(Boolean progressive)
Set the progressive flag.void
setQuality(Float quality)
Sets the quality of the resized image in pixels.void
setShrinkonly(Boolean shrinkonly)
Set the shrink-only flag.void
setVar(String var)
Specifies the JSP variable to store the result in.void
setWidth(Integer width)
Sets the width of the resized image in pixels.
-
-
-
Method Detail
-
setVar
public void setVar(String var)
Specifies the JSP variable to store the result in.- Parameters:
var
- a jsp variable name
-
setImage
public void setImage(Image image)
Specifies the image object to resize.- Parameters:
image
- an image object
-
setWidth
public void setWidth(Integer width)
Sets the width of the resized image in pixels.- Parameters:
width
- in pixels
-
setHeight
public void setHeight(Integer height)
Sets the height of the resized image in pixels.- Parameters:
height
- in pixels
-
setQuality
public void setQuality(Float quality)
Sets the quality of the resized image in pixels.- Parameters:
quality
- between 0 and 1
-
setMode
public void setMode(String mode)
Set the mode. The mode determines how the image is scaled and cropped to match the requested target dimensions. There are two mode available, CROP and SCALE.CROP scales the image such that it completely covers the target dimensions. Any parts of the image that fall outside the target are cropped off. This mode generates a resulting image which has the exact same dimensions as the requested target dimensions.
SCALE scale the image such that it neatly fits completely inside the target dimensions. This mode can generate a result image with dimensions which are different (smaller) than the requested target dimensions.
Both modes preserve the image's aspect ratio. The default is CROP.
- Parameters:
mode
- One of the following strings: "CROP" or "SCALE".- Since:
- WebManager 9.17
-
setShrinkonly
public void setShrinkonly(Boolean shrinkonly)
Set the shrink-only flag. This flag controls whether the image should be scaled up (made bigger) to match the requested dimensions. If set to true, then the image will only be scaled down (shrunk) and never scaled up.If this flag is not set then it defaults to false.
- Parameters:
mode
-- Since:
- WebManager 9.17
-
setProgressive
public void setProgressive(Boolean progressive)
Set the progressive flag. This flag controls whether the image should be saved as a progressive image when possible.If this flag is not set then it defaults to false.
- Parameters:
progressive
-- Since:
- WebManager 10.21
-
doTag
public void doTag() throws javax.servlet.jsp.JspException
- Specified by:
doTag
in interfacejavax.servlet.jsp.tagext.SimpleTag
- Overrides:
doTag
in classjavax.servlet.jsp.tagext.SimpleTagSupport
- Throws:
javax.servlet.jsp.JspException
-
-