Image orientation feature
When users upload an image, censhare automatically determines dimensions and calculates an aspect ratio (landscape, square, portrait). The value is stored in the respective asset property. The feature is part of the censhare standard workspace. You can customize this feature, if necessary.
Context
The feature and the value expression are configured in the censhare Admin Client.
Prerequisites
None.
Introduction
The aspect ratio of an image determines its usage and is therefor a key image parameter. The Image orientation feature in the censhare master data calculates the aspect ratio and assigns one of three default values to a picture:
Landscape: Height greater than width
Portrait: Width greater than height
Square: Same height and width
The standard with the default values works out of the box. If you want to use more detailed values than the defaults, you can customize the value expression of the feature.
Default configuration
The feature is part of the censhare standard workspace:
In the censhare Admin Client, open the Master data/Features table.
Search for the Image orientation feature (ID: censhare:image-orientation), and double-click to open.
The Value type of the feature is Value list (String).
The Value expression field contains the JavaScript function that assigns the respective values.
The Values section at the bottom contains the possible values.
Value expression
The default value expression is defined as follows:
if (substring(./@type,1,8)='picture.')
then
(if ((./storage_item[@key='preview']/@height_px)
and (./storage_item[@key='preview']/@width_px))
then
(if((number(./storage_item[@key='preview']/@height_px)
gt number(./storage_item[@key='preview']/@width_px)))
then ('portrait')
else (if (number(./storage_item[@key='preview']/@height_px)
lt number(./storage_item[@key='preview']/@width_px))
then ('landscape')
else ('square')))
else ())
else()
First, the expression checks if the context asset is an image.
Next, the expression checks if values for height and width exist.
Now, the expression compares the height and width value, and assigns one of the three values "landscape", "portrait" or "square".
The values correspond to the value items that are configured in the feature value list.
Customization
The standard feature cannot be changed. If you want to use a custom aspect ratio feature, do the following:
In the censhare Admin Client, open the Master data/Features table.
Search for the Image orientation feature (ID: censhare:image-orientation).
Select the feature, and click an icon to duplicate it.
Fill out the required fields. Do not change the value type!
In the Value expression field, paste the custom JavaScript according to your purposes.
Edit the value list to match the custom values that are assigned in the JavaScript.
Click OK to save.
Restart the censhare Server.
To make the custom feature available in censhare Web, you must add it to the respective dialogs of the Image properties widget configurations and Edit properties dialogs. For more information, see Image transformation variants cropping.
Example
The following example adds the value panorama to the image orientation feature for images with an aspect ratio greater than 1:3 (height : width):
if (substring(./@type,1,8)='picture.')
then (if ((./storage_item[@key='preview']/@height_px)
and (./storage_item[@key='preview']/@width_px))
then (if ((number(./storage_item[@key='preview']/@height_px)
gt number(./storage_item[@key='preview']/@width_px)))
then ('portrait')
else (if (number(./storage_item[@key='preview']/@height_px)
lt number(./storage_item[@key='preview']/@width_px))
then (if ((number(./storage_item[@key='preview']/@height_px)*3
lt number(./storage_item[@key='preview']/@width_px)))
then ('panorama')
else ('landscape'))
else ('square')))
else ())
else()
The value panorama must be added to the value list of the feature.
Result
When a user adds an image asset, the Image orientation property is automatically set in the asset.
Related content
For more information, see this article.