Gentics Content.Node GenticsImageStore

The GenticsImageStore is a feature that can be used to embed resized images in pages and overviews.

The GenticsImageStore is not capable of resizing images that use a CMYK color palette. Currently only RGB images are supported.

1 Usage

/GenticsImageStore/[width]/[height]/[mode]/[imageurl]

Example:


<img src="/GenticsImageStore/<node width>/auto/prop/<node bild>">

1.1 Prop, force, smart mode

/GenticsImageStore/[width]/[height]/[mode]/[imageurl]
Parameter Description
width Image width
height Image height
mode Resizing Mode
imageurl Image url

The following modes are available:

  • prop used for proportional resizing. The aspect ratio of the image will be preserved. When target width and height do not match the original image proportions the lower value (height, width) will be used for resizing.
  • force used for forced resizing. The aspect ratio of the original image will not be preserved when this mode is beeing used.
  • smart used for automatic resizing and cropping of images.

1.2 Crop and resize mode

Available after Gentics Portal.Node Update 11432 2011-06-01

Additionally the special ‘cropandresize’ mode can be used to crop images.

/GenticsImageStore/[width]/[height]/cropandresize/[mode]/[topleft_x]/[topleft_y]/[cropwidth]/[cropheight]/[imageurl]

Parameter:

Name Description
width Image width
height Image height
mode Resizing Mode (see prop,force,smart)
topleft_x Start X coordinate of the image area (starting top left cornor)
topleft_y Start Y coordinate of the image area (starting top left cornor)
cropwidth Image area width
cropheight Image area height
imageurl Imageurl

2 Gentics Content.Node

2.1 Static Cross Node Projects

The GenticsImageStore is also able to resize images in foreign nodes. A page in node A may contain the following image url:


http://www.node-b-hostname.tdl/GenticsImageStore/300/auto/prop/Content.Node/images/flower.jpg

Such an url will be identified by the GenticsImageStore during the publish process. The GenticsImageStore identifies the referenced node by examining the hostname within the found url. The image within node B will be resized when the GenticsImageStore determined that the referenced node (in this case node b) is publishing into the filesystem. Resizing will otherwise be omitted.

The image tag must be adapted to include the node B hostname.

Example velocity implementation:

velocity example

#set( $nodePath = "$cms.tag.parts.src.target.folder.node.path")
#set( $pubdir = "$cms.tag.parts.src.target.folder.pub_dir")
#set( $imagePath = "$cms.tag.parts.src.target.name")

## Remove the trailing slash from the pub_dir
#set( $pubdir = $pubdir.trim())
#if($pubdir.endsWith("/"))
#set( $len = $cms.imps.velocitytools.math.sub($pubdir.length(),1) ) 
#set( $pubdir = $pubdir.substring(0, $len))
#end

## Remove the trailing slash from the nodePath
#set( $nodePath = $nodePath.trim())
#if($nodePath.endsWith("/"))
#set( $len = $cms.imps.velocitytools.math.sub($nodePath.length(),1) ) 
#set( $nodePath = $nodePath.substring(0, $len))
#end

#if($cms.rendermode.publish) 
<img  src="http://${cms.tag.parts.src.target.folder.node.host}/GenticsImageStore/300/auto/prop${nodePath}${pubdir}/${imagePath}"/>
#else
<img src="/GenticsImageStore/300/auto/prop/$cms.tag.parts.src.target.url" />
#end 

2.2 Publishing

Resized images will be written to the filesystem when the GenticsImageStore was used within the project. The usage will be determined by examining the final page content. All GenticsImageStore urls will be processed. The GenticsImageStore will invoke the resizing of a page when the GenticsImageStore found a resize call within a published page. The resized image will be written in a folder called GenticsImageStore within the pub directory of that particular node. Please note that this directory has to be synced to the target webserver as well.

3 Servlet Parameters

The GenticsImageStore can be used within Portal implementations. The configuration will be performed using the following servlet parameters.

3.1 cacheKeyQueryParameters

Available after Gentics Portal.Node Update 11432 2011-06-01

This parameter can be used to modify the internally used cache key for cached images. It is possible to specify certain get parameters. Those parameters will than be used (if available) to enhance the cache.key. Normally all other query parameters will not be used for generating the cache key. The parameters can be specified in a comma separated list. This parameter is useful when the images will be retrieved using a servlet that uses query parameters to identify the image that should be loaded.

Example:


	<init-param>
			<param-name>cacheKeyQueryParameters</param-name>
			<param-value>contentid,type,mycustomparam</param-value>
	</init-param>

3.2 portalBasePath

Available after Gentics Portal.Node Update 11432 2011-06-01

The portal base path is used to identify the image url within a GenticsImageStore url. The default value is “/Portal.Node”. The used prefix can be adapted using this parameter. This is useful of images will not be delivered by Portal.Node.


	<init-param>
			<param-name>portalBasePath</param-name>
			<param-value>/MyWebapp</param-value>
	</init-param>

3.3 portalBasePathRegEx

Available after Gentics Portal.Node Update Update 11779 2011-11-29

This parameter has the same functionality as the portalBasePath. It is possible to configure multiple basepaths by using a regular expression. When set this parameter will be prefered.


	<init-param> 
		<param-name>portalBasePathRegEx</param-name> 
		<param-value>(\/Portal\.Node.*)|(\/GCN5_Portal.*)</param-value> 
	</init-param>

3.4 urlPrefix

By default the image will be loaded from the host which got the initial GenticsImageStore request. The urlPrefix setting can be used when the image should be loaded from a different host.


	<init-param> 
		<param-name>urlPrefix</param-name> 
		<param-value>http://localhost:8080/</param-value> 
	</init-param> 

3.5 uriMapper

An addition to the uriPrefix is the uriMapper parameter. This parameter allows to specify a custom implementation that is able to modify the image uri. It is therefore possible to customize the uri according to set uri parameters or hostnames.

To achieve this one has to implement the interface com.gentics.api.imagestore.ImageUriMapper. The name of the implemented class has to be set as value for the “uriMapper” parameter. Please note that the full package name has to be specified. The implemented class must be able to be loaded by the Servlet ClassLoader.

Interface:


public interface ImageUriMapper {

	/**
	 * Maps a request for an image to an URI where the image can be fetched from.
	 * 
	 * This method should have no side effects and should always return the same URI
	 * for the given imageUri and the parameters in the given servletRequest.
	 * 
	 * Further, this method should be idempotent such that passing back the returned URI
	 * to this method again returns the given URI unchanged.
	 * 
	 * @param servletRequest
	 * 		  The request that fetches the image.
	 * @param imageUri
	 * 		  The URI of the image to fetch.
	 * @return
	 * 		  May either return the given URI unchanged, or an alternate URI
	 * 		  where the image will be fetched from instead.
	 */


	URI mapImageUri(HttpServletRequest servletRequest, URI imageUri);

}

	<init-param> 
		<param-name>uriMapper</param-name> 
		<param-value>com.example.ImageUriMapperImpl</param-value> 
	</init-param>

4 Caching

The GenticsImageStore uses the JCS Cache which can be configured using the cache.ccf file.

Example Cache Region Configuration:

cache.ccf

jcs.region.gentics-content-imagestorecache=DC
jcs.region.gentics-content-imagestorecache.cacheattributes.MaxObjects=0
jcs.region.gentics-content-imagestorecache.elementattributes.MaxLifeSeconds=86400