Class CmsJspTagScaleImage
- All Implemented Interfaces:
Serializable
,javax.servlet.jsp.tagext.BodyTag
,javax.servlet.jsp.tagext.IterationTag
,javax.servlet.jsp.tagext.JspTag
,javax.servlet.jsp.tagext.Tag
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:
-
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
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
doEndTag()
Does some cleanup before returning EVAL_PAGEint
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, String imageUri, CmsImageScaler targetScaler, List<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
(String value) Sets the String containing a comma separated list of hi-DPI variants to produce line "1.3x,1.5x,2x,3x".void
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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
-
Constructor Details
-
CmsJspTagScaleImage
public CmsJspTagScaleImage()Creates a new image scaling tag instance.
-
-
Method Details
-
imageTagAction
public static CmsJspImageBean imageTagAction(CmsObject cms, String imageUri, CmsImageScaler targetScaler, List<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
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
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
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
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
Sets the name of the variable used for storing the resulting bean.- Parameters:
value
- name of the resulting CmsJspScaledImage bean
-