Class CmsJspTagScaleImage
- java.lang.Object
-
- javax.servlet.jsp.tagext.TagSupport
-
- javax.servlet.jsp.tagext.BodyTagSupport
-
- org.opencms.jsp.CmsJspImageScalerTagSupport
-
- org.opencms.jsp.CmsJspTagScaleImage
-
- All Implemented Interfaces:
java.io.Serializable
,javax.servlet.jsp.tagext.BodyTag
,javax.servlet.jsp.tagext.IterationTag
,javax.servlet.jsp.tagext.JspTag
,javax.servlet.jsp.tagext.Tag
public class CmsJspTagScaleImage extends CmsJspImageScalerTagSupport
This tag allows using the OpenCms native image scaling mechanism within JSP.No output is generated by this tag! Instead the tag generates a
CmsJspImageBean
. This can be used to further process the selected image with the provided image scaling parameters.The following image formats are supported: BMP, GIF, JPEG, PNG, PNM, TIFF.
Note: Picture scaling is by default only enabled for target size with width and height <=1500. The size can be changed in the image scaler configuration in the file
opencms-vfs.xml
in the body of the tag<loader>
. Also other options for the image scaler are set there.This tag is an alternative to the OpenCms standard tag cms:img, providing additional flexibility. This way you can use scaled images for:
- The standard HTML <img>-Tag.
- The HTML 5 <picture>-Tag with multiple sources (hi-DPI variants for retina displays) for responsive design.
- Further processing a scaled image anyway you want on your JSP.
Example for a simple JSP that uses this tag to obtain information about an image:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<cms:scaleImage var="imgBean" src="/.galleries/samples/09.jpg?__scale=h:385,w:961,cx:42,cy:32,ch:385,cw:961" />
srcUrl: <c:out value="${imgBean.srcUrl}" /><br>
vfsUri: <c:out value="${imgBean.vfsUri}" /><br>
scalerParams: <c:out value="${imgBean.scaler.requestParam}" /><br>
Width: <c:out value="${imgBean.width}" /><br>
Height: <c:out value="${imgBean.height}" /><br>
scaledWidth: <c:out value="${imgBean.scaler.width}" /><br>
scaledHeight: <c:out value="${imgBean.scaler.height}" /><br>
isScaled: <c:out value="${imgBean.scaled}" /><br>
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.opencms.jsp.CmsJspImageScalerTagSupport
m_scaler, m_src, SCALE_ATTR_HEIGHT, SCALE_ATTR_MAXHEIGHT, SCALE_ATTR_MAXWIDTH, SCALE_ATTR_POSITION, SCALE_ATTR_QUALITY, SCALE_ATTR_RENDERMODE, SCALE_ATTR_TYPE, SCALE_ATTR_WIDTH
-
-
Constructor Summary
Constructors Constructor Description CmsJspTagScaleImage()
Creates a new image scaling tag instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
doEndTag()
Does some cleanup before returning EVAL_PAGEint
doStartTag()
Handles the Start tag, checks some parameters, uses the CmsImageScaler to create a scaled version of the image (and hi-DPI variants if necessary), stores all information in a image bean and stores it as a request attribute (the name for this attribute is given with the tag attribute "var").static CmsJspImageBean
imageTagAction(CmsObject cms, java.lang.String imageUri, CmsImageScaler targetScaler, java.util.List<java.lang.String> hiDpiVariantList)
Internal action method to create the scaled image bean.void
release()
Does some cleanup before the tag is released to the tag poolvoid
setHiDpiVariants(java.lang.String value)
Sets the String containing a comma separated list of hi-DPI variants to produce line "1.3x,1.5x,2x,3x".void
setVar(java.lang.String value)
Sets the name of the variable used for storing the resulting bean.-
Methods inherited from class org.opencms.jsp.CmsJspImageScalerTagSupport
getHeight, getMaxHeight, getMaxWidth, getScaleColor, getScaleFilter, getScalePosition, getScaleQuality, getScaleRendermode, getScaleType, getSrc, getWidth, setHeight, setMaxHeight, setMaxWidth, setScaleColor, setScaleFilter, setScalePosition, setScaleQuality, setScaleRendermode, setScaleType, setSrc, setWidth
-
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doAfterBody, doInitBody, getBodyContent, getPreviousOut, setBodyContent
-
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
-
-
-
-
Constructor Detail
-
CmsJspTagScaleImage
public CmsJspTagScaleImage()
Creates a new image scaling tag instance.
-
-
Method Detail
-
imageTagAction
public static CmsJspImageBean imageTagAction(CmsObject cms, java.lang.String imageUri, CmsImageScaler targetScaler, java.util.List<java.lang.String> hiDpiVariantList) throws CmsException
Internal action method to create the scaled image bean.- Parameters:
cms
- the cms contextimageUri
- the image URItargetScaler
- the target image scalerhiDpiVariantList
- optional list of hi-DPI variant sizes to produce, e.g. 1.3x, 1.5x, 2x, 3x- Returns:
- the created ScaledImageBean bean
- Throws:
CmsException
- in case something goes wrong
-
doEndTag
public int doEndTag() throws javax.servlet.jsp.JspException
Does some cleanup before returning EVAL_PAGE- Specified by:
doEndTag
in interfacejavax.servlet.jsp.tagext.Tag
- Overrides:
doEndTag
in classjavax.servlet.jsp.tagext.BodyTagSupport
- Throws:
javax.servlet.jsp.JspException
- See Also:
Tag.doEndTag()
-
doStartTag
public int doStartTag()
Handles the Start tag, checks some parameters, uses the CmsImageScaler to create a scaled version of the image (and hi-DPI variants if necessary), stores all information in a image bean and stores it as a request attribute (the name for this attribute is given with the tag attribute "var").- Specified by:
doStartTag
in interfacejavax.servlet.jsp.tagext.Tag
- Overrides:
doStartTag
in classjavax.servlet.jsp.tagext.BodyTagSupport
- Returns:
- EVAL_BODY_INCLUDE or SKIP_BODY in case of an unexpected Exception (please consult the OpenCms log file if that happens)
-
release
public void release()
Does some cleanup before the tag is released to the tag pool- Specified by:
release
in interfacejavax.servlet.jsp.tagext.Tag
- Overrides:
release
in classCmsJspImageScalerTagSupport
- See Also:
Tag.release()
-
setHiDpiVariants
public void setHiDpiVariants(java.lang.String value)
Sets the String containing a comma separated list of hi-DPI variants to produce line "1.3x,1.5x,2x,3x".Currently in most cases "2x" should suffice to generate an additiona image for retina screens. Please note that since 11.0 the variants are created by lazy initialization, so there is usually no need to use this.
- Parameters:
value
- comma separated list of hi-DPI variants to produce, e.g. "1.3x,1.5x,2x,3x"
-
setVar
public void setVar(java.lang.String value)
Sets the name of the variable used for storing the resulting bean.- Parameters:
value
- name of the resulting CmsJspScaledImage bean
-
-