This page explains how to work with images using
imgfntemplating
functions in template scripts. With imgfn you can get an image from
any JCR workspace.
If you use a Magnolia bundle, the required and optional modules are
already included.
If you
created
a custom webapp, add the following modules in the POM file of the
webapp of your bundle. The modules may have dependencies to other
modules but these dependencies are handled by Maven dependency
management.
Required modules
Modules required for basic image operations.
artifactId
version
magnolia-module-imaging
3.5.12
magnolia-imaging-support
3.5.12
Optional modules
Modules required when using size variations of an image. Recommended.
artifactId
version
magnolia-site
1.4.7
magnolia-templating-essentials-imaging
2.0.6
Uploading the image with a basic upload field
With a
basic
upload field you can upload an image directly to the node of your
context. When saving the data of the dialog, Magnolia creates a subnode
of the node of your context and stores the binary data of the image as
property of the subnode.
If the dialog is for a
Component,
the system creates a subnode of the component node.
If the dialog is for a an item of a content
app, the system creates a subnode of the content item node.
In the dialog definition, you can define the value of the
binaryNodeName property (in the example the value is myNode). Keep
in mind that you must know the name of this subnode to render the image
later on.
You can check the JCR node structure in in the
JCR Browser app.
Displaying an image variation using imgfn
Using imgfn, you can create a link to an image stored in any workspace
as long as you know the path to the node which stores the binary data of
the image.
Look at the screenshot above showing the JCR browser. It highlights the
subnode of a component node. Within the rendering context of a component
template script you have the
content
object which is the component node. In the screenshot above, the node
with the name 0 is the content object.
To display an image, you must get the subnode of content and pass it
as argument to the imgfn templating function. You can use the same
method to get the original version of the image and to get a variation.