public class CmsJspImageBean extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
CmsJspImageBean.CmsScaleHiDpiTransformer
Provides a Map to access hi-DPI versions of the current image.
|
class |
CmsJspImageBean.CmsScaleRatioTransformer
Provides a Map to access ratio scaled versions of the current image.
|
class |
CmsJspImageBean.CmsScaleWidthTransformer
Provides a Map to access width scaled versions of the current image.
|
Modifier and Type | Field and Description |
---|---|
static int |
MIN_DIMENSION
The minimum dimension (width and height) a generated image must have.
|
Modifier | Constructor and Description |
---|---|
protected |
CmsJspImageBean()
Initializes a new empty image bean.
|
|
CmsJspImageBean(CmsObject cms,
CmsResource imageRes,
java.lang.String scaleParams)
Initializes a new image bean based on a VFS resource and optional scaler parameters.
|
|
CmsJspImageBean(CmsObject cms,
java.lang.String imageUri)
Initializes a new image bean based on a string pointing to a VFS resource that may contain appended scaling parameters.
|
|
CmsJspImageBean(CmsObject cms,
java.lang.String imageUri,
CmsImageScaler initScaler)
Initializes a new image bean based on a VFS input string and applies additional re-scaling.
|
Modifier and Type | Method and Description |
---|---|
void |
addHiDpiImage(java.lang.String factor,
CmsJspImageBean image)
adds a CmsJspImageBean as hi-DPI variant to this image
|
void |
addSrcSetWidthVariants(int minWidth,
int maxWidth)
Adds a number of size variations to the source set.
|
protected java.lang.String |
calcRatioHeightPercentage(double width,
double height)
Returns the ratio height percentage of an image based on width and height.
|
CmsJspImageBean |
createHiDpiVariation(java.lang.String hiDpiStr)
Creates a hi-DPI scaled version of the current image.
|
CmsJspImageBean |
createRatioVariation(java.lang.String ratioStr)
Creates a ratio scaled version of the current image.
|
protected CmsJspImageBean |
createVariation(CmsImageScaler targetScaler)
Returns a variation of the current image scaled with the given scaler.
|
protected static CmsImageScaler |
createVariation(int originalWidth,
int originalHeight,
CmsImageScaler baseScaler,
int targetWidth,
int targetHeight,
int quality)
Create a variation scaler fir this image.
|
CmsJspImageBean |
createWidthVariation(java.lang.String widthStr)
Creates a width scaled version of the current image.
|
protected CmsImageScaler |
getBaseScaler()
Sets the scaler that describes the basic adjustments (usually cropping) that have been set on the original image.
|
protected CmsObject |
getCmsObject()
Returns the current OpenCms user context.
|
int |
getHeight()
Returns the original pixel height of the image.
|
java.util.Map<java.lang.String,CmsJspImageBean> |
getHiDpiImages()
Deprecated.
use
getScaleHiDpi() instead |
java.lang.String |
getImgSrc()
Returns the basic source parameters for this image.
|
protected CmsImageScaler |
getOriginalScaler()
Returns the image scaler that describes the original proportions of this image.
|
int |
getQuality()
Returns the compression quality factor used for image generation.
|
java.lang.String |
getRatio()
Returns the image ratio.
|
java.lang.String |
getRatioHeightPercentage()
Returns the image height percentage relative to the image width as a String.
|
CmsJspResourceWrapper |
getResource()
Returns the JSP access wrapped VFS resource for this image.
|
java.util.Map<java.lang.String,CmsJspImageBean> |
getScaleHiDpi()
Returns a lazy initialized Map that provides access to hi-DPI scaled instances of this image bean.
|
CmsImageScaler |
getScaler()
Returns the image scaler that is used for the scaled version of this image bean.
|
java.util.Map<java.lang.String,CmsJspImageBean> |
getScaleRatio()
Returns a lazy initialized Map that provides access to ratio scaled instances of this image bean.
|
java.util.Map<java.lang.String,CmsJspImageBean> |
getScaleWidth()
Returns a lazy initialized Map that provides access to width scaled instances of this image bean.
|
protected CmsJspImageBean |
getSelf()
Returns this instance bean, required for the transformers.
|
java.lang.String |
getSrcSet()
Generates a srcset attribute parameter list from all images added to this image bean.
|
java.lang.String |
getSrcSetEntry()
Generates a srcset attribute parameter for this image bean.
|
java.util.Map<java.lang.Integer,CmsJspImageBean> |
getSrcSetMap()
Returns the source set map.
|
CmsJspImageBean |
getSrcSetMaxImage()
Returns the largest image from the generated source set.
|
int |
getSrcSetMaxWidth()
Returns the largest width value form the source set.
|
CmsJspImageBean |
getSrcSets()
Getter for
setSrcSets(CmsJspImageBean) which returns this image bean. |
java.lang.String |
getSrcUrl()
Returns the image URL that may be used in img or picture tags.
|
java.lang.String |
getVfsUri()
Returns the URI of the image in the OpenCms VFS.
|
int |
getWidth()
Returns the original (unscaled) width of the image.
|
protected void |
init(CmsObject cms,
CmsResource imageRes,
java.lang.String scaleParams)
Initializes this new image bean based on a VFS resource and optional scaler parameters.
|
boolean |
isImage()
Returns
true if this image bean has been correctly initialized with an image VFS resource. |
boolean |
isScaled()
Returns
true if the image has been scaled or otherwise processed. |
protected void |
setBaseScaler(CmsImageScaler baseScaler)
Returns the scaler that describes the basic adjustments (usually cropping) that have been set on the original image.
|
protected void |
setCmsObject(CmsObject cms)
Sets the current OpenCms user context.
|
protected void |
setOriginalScaler(CmsImageScaler originalScaler)
Sets the scaler that describes the original proportions of this image.
|
void |
setQuality(int quality)
Sets the compression quality factor to use for image generation.
|
protected void |
setResource(CmsObject cms,
CmsResource resource)
Sets the CmsResource for this image.
|
protected void |
setScaler(CmsImageScaler scaler)
Sets the image scaler that was used to create this image.
|
void |
setSrcSetQuality()
Adjusts the quality settings for all image beans in the srcSet depending on the pixel count.
|
void |
setSrcSets(CmsJspImageBean imageBean)
Adds another image bean instance to the source set map of this bean.
|
void |
setVfsUri(java.lang.String vfsUri)
Sets the URI of the image in the OpenCms VFS.
|
java.lang.String |
toString()
Returns the image source URL as String representation.
|
public static int MIN_DIMENSION
public CmsJspImageBean(CmsObject cms, CmsResource imageRes, java.lang.String scaleParams)
cms
- the current OpenCms user contextimageRes
- the VFS resource to read the image fromscaleParams
- optional scaler parameters to apply to the VFS resourcepublic CmsJspImageBean(CmsObject cms, java.lang.String imageUri) throws CmsException
cms
- the current OpenCms user contextimageUri
- the URI to read the image from in the OpenCms VFS, may also contain appended scaling parametersCmsException
- in case of problems reading the image from the VFSpublic CmsJspImageBean(CmsObject cms, java.lang.String imageUri, CmsImageScaler initScaler) throws CmsException
The input string is is used to read the images from the VFS. It can contain scaling parameters. The additional re-scaling is then applied to the image that has been read.
cms
- the current uses OpenCms contextimageUri
- the URI to read the image from in the OpenCms VFS, may also contain scaling parametersinitScaler
- the additional re-scaling to apply to the imageCmsException
- in case of problems reading the image from the VFSprotected CmsJspImageBean()
All values must be set with setters later.
protected static CmsImageScaler createVariation(int originalWidth, int originalHeight, CmsImageScaler baseScaler, int targetWidth, int targetHeight, int quality)
originalWidth
- the original image pixel widthoriginalHeight
- the original image pixel heightbaseScaler
- the base scaler that may contain crop parameterstargetWidth
- the target image pixel widthtargetHeight
- the target image pixel heightquality
- the compression quality factor to use for image generationpublic void addHiDpiImage(java.lang.String factor, CmsJspImageBean image)
factor
- the variant multiplier, e.g. "2x" (the common retina multiplier)image
- the image to be used for this variantpublic void addSrcSetWidthVariants(int minWidth, int maxWidth)
In case the screen size is not really known, it may be a good idea to add some variations for large images to make sure there are some common options in case the basic image is very large.
minWidth
- the minimum image width to add size variations formaxWidth
- the maximum width size variation to createpublic CmsJspImageBean createHiDpiVariation(java.lang.String hiDpiStr)
hiDpiStr
- the hi-DPI variation to generate, for example "2.5x".public CmsJspImageBean createRatioVariation(java.lang.String ratioStr)
ratioStr
- the rato variation to generate, for example "4-3" or "1-1".public CmsJspImageBean createWidthVariation(java.lang.String widthStr)
widthStr
- the with variation to generate, for example "1078" or "800".public int getHeight()
@Deprecated public java.util.Map<java.lang.String,CmsJspImageBean> getHiDpiImages()
getScaleHiDpi()
insteadpublic java.lang.String getImgSrc()
In case the image was cropped or otherwise manipulated, the values are created for the manipulated version.
The return form is "src='(srcUrl)' height='(h)' width='(w)'".
public int getQuality()
public java.lang.String getRatio()
The ratio is in the form 'width-height', for example '4-3' or '16-9'. In case no ratio was set, the pixel dimensions of the image are returned.
public java.lang.String getRatioHeightPercentage()
In case a ratio has been used to scale the image, the height percentage is calculated based on the ratio, not on the actual image pixel size. This is done to avoid rounding differences.
public CmsJspResourceWrapper getResource()
public java.util.Map<java.lang.String,CmsJspImageBean> getScaleHiDpi()
public CmsImageScaler getScaler()
public java.util.Map<java.lang.String,CmsJspImageBean> getScaleRatio()
public java.util.Map<java.lang.String,CmsJspImageBean> getScaleWidth()
public java.lang.String getSrcSet()
public java.lang.String getSrcSetEntry()
public java.util.Map<java.lang.Integer,CmsJspImageBean> getSrcSetMap()
In case no source set entries have been added before, the map is not initialized and null
is returned.
public CmsJspImageBean getSrcSetMaxImage()
In case the source set has not been initialized, it returns the instance itself.
public int getSrcSetMaxWidth()
In case no source set entries have been added before, the map is not initialized and 0
is returned.
public CmsJspImageBean getSrcSets()
setSrcSets(CmsJspImageBean)
which returns this image bean.
Exists to make sure setSrcSets(CmsJspImageBean)
is available as property on a JSP.
getSrcSet()
,
getSrcSetMap()
public java.lang.String getSrcUrl()
public java.lang.String getVfsUri()
public int getWidth()
public boolean isImage()
true
if this image bean has been correctly initialized with an image VFS resource.true
if this image bean has been correctly initialized with an image VFS resourcepublic boolean isScaled()
true
if the image has been scaled or otherwise processed.true
if the image has been scaled or otherwise processedpublic void setQuality(int quality)
quality
- the compression quality factor to use for image generationpublic void setSrcSetQuality()
The idea is to make sure large pixel images use a higher JPEG compression in order to reduce the size.
The following quality settings are used depending on the image size:
public void setSrcSets(CmsJspImageBean imageBean)
imageBean
- the image bean to addpublic void setVfsUri(java.lang.String vfsUri)
vfsUri
- the URI of the image in the OpenCms VFS to setpublic java.lang.String toString()
toString
in class java.lang.Object
getSrcUrl()
protected java.lang.String calcRatioHeightPercentage(double width, double height)
width
- width to calculate percentage fromheight
- height to calculate percentage fromprotected CmsJspImageBean createVariation(CmsImageScaler targetScaler)
It is always the original image which is used as a base, never a scaled version. So for example if the image has been cropped by the user, the cropping are is ignored.
targetScaler
- contains the information about how to scale the imageprotected CmsImageScaler getBaseScaler()
protected CmsObject getCmsObject()
protected CmsImageScaler getOriginalScaler()
protected CmsJspImageBean getSelf()
protected void init(CmsObject cms, CmsResource imageRes, java.lang.String scaleParams)
cms
- the current OpenCms user contextimageRes
- the VFS resource to read the image fromscaleParams
- optional scaler parameters to apply to the VFS resourceprotected void setBaseScaler(CmsImageScaler baseScaler)
baseScaler
- the scaler that describes the basic adjustments (usually cropping) that have been set on the original imageprotected void setCmsObject(CmsObject cms)
cms
- the current OpenCms user context to setprotected void setOriginalScaler(CmsImageScaler originalScaler)
originalScaler
- the scaler that describes the original proportions of this imageprotected void setResource(CmsObject cms, CmsResource resource)
cms
- the current OpenCms user context, required for wrapping the resourceresource
- the VFS resource for this imageprotected void setScaler(CmsImageScaler scaler)
scaler
- the image scaler that was used to create this image.