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_WIDTHFields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContentFields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContextFields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAGFields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAINFields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdoEndTag()Does some cleanup before returning EVAL_PAGEintHandles 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 CmsJspImageBeanimageTagAction(CmsObject cms, String imageUri, CmsImageScaler targetScaler, List<String> hiDpiVariantList) Internal action method to create the scaled image bean.voidrelease()Does some cleanup before the tag is released to the tag poolvoidsetHiDpiVariants(String value) Sets the String containing a comma separated list of hi-DPI variants to produce line "1.3x,1.5x,2x,3x".voidSets 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, setWidthMethods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doAfterBody, doInitBody, getBodyContent, getPreviousOut, setBodyContentMethods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
doEndTagin interfacejavax.servlet.jsp.tagext.Tag- Overrides:
doEndTagin classjavax.servlet.jsp.tagext.BodyTagSupport- Throws:
javax.servlet.jsp.JspException- See Also:
-
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:
doStartTagin interfacejavax.servlet.jsp.tagext.Tag- Overrides:
doStartTagin 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:
releasein interfacejavax.servlet.jsp.tagext.Tag- Overrides:
releasein classCmsJspImageScalerTagSupport- See Also:
-
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
-