Cropping an image
Cropping an image
WMS_BO_cropping
Section(s): back office, ergonomics, plugin, standard plugin
Brief description
Adds the ability to crop an image into different shapes. Cropped images are then known as variations of the original image. It is easy in FO to check if a variation of the image exists in a specific cropping format and to use it.
Requirements
This plugin requires the following objects to exist :
- picturecrop

- picturecroptype

- The image to be cropped to be a property named image in an object with a collection of picturecrop
Getting started
The galleryelement object (provided with WMS - required for the gallery plugin) implements a crop collection property. It is a good start to see how object is configured.
Make sure the picturecrop and picturecroptype structures exists on your system
Create a foo object with an image property of type image.
Add a crop property (collection of picturecrop) to the foo object
Ensure you have at least one picturecroptype.
What is this picturecroptype about?
the picturecroptype object gives you cropping types : you can define several cropping formats.
When defining one, you specify
- its name (eg landscape, portrait, square...) be careful to give more of a name, a code, easy to query in FO and easy to translate thanks to wcmcaption,
- its minimum width and height (croped images won't necessary be of those width and height, they could be bigger, but they won't be smaller), and they will be of that proportion (homothetic)
What should I do in FO?
In FO, you might want to check if an appropriate variation of the image exists for the template. For exemple, if you have a SQUARE named croptype of ID 1configured with 50x50, that your activeObject has an image property, before writing the image property in your template, you should do :
<%-- We are retrieving the parent property of activeObject --%>
<c:set var="currParent" value="${activeObject.properties.parent}"/>
<%-- If not empty, we add an _ at the end --%>
<c:if test="${not empty currParent}">
<c:set var="currParent" value="${currParent}_"/>
</c:if>
<%-- We add activeObject key --%>
<c:set var="currParent" value="${currParent}${activeObject.type}_${activeObject.identity}"/>
<%-- At this point, we can load picturecrop as composition of
activeObject. --%>
<%--
Note that this technic for retrieving the parent key value is the most
generic (it will always be fine regardless of activeObject being or
not a collection item).
However, if you are sure activeObject cannot be a collection item,
then you can very simply get the currParent this way :
<c:set var="currParent" value="${activeObject.type}_${activeObject.identity}"/>
--%>
<%-- Building the query --%>
<noheto:where base="basewhere_view_picturecrop" where="ptype=? AND pparent=?" var="getCrop">
<noheto:whereParameter type="int" value="1"/>
<noheto:whereParameter type="string" value="${currParent}"/>
</noheto:where>
<c:set var="found" value="false"/>
<noheto:objectsList objectName="picturecrop" where="${getCrop}" nbrMax="1" var="crop">
<noheto:image width="50" src="/image/${crop.type}/${crop.properties.image}"/>
<c:set var="found" value="true"/>
</noheto:objectsList>
<c:if test="${not found}">
<noheto:image width="50" src="/image/${activeObject.type}/${activeObject.properties.image}"/>
</c:if>
