Class 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
    • Constructor Detail

    • 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 context
        imageUri - the image URI
        targetScaler - the target image scaler
        hiDpiVariantList - 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 interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doEndTag in class javax.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 interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doStartTag in class javax.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 interface javax.servlet.jsp.tagext.Tag
        Overrides:
        release in class CmsJspImageScalerTagSupport
        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