Skip to main content
Skip table of contents

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, therefore, 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:

  1. In the censhare Admin Client, open the Master data/Features table.

  2. Search for the Image orientation feature (ID: censhare:image-orientation), and double-click to open.

  3. The Value type of the feature is Value list (String).

  4. The Value expression field contains the JavaScript function that assigns the respective values.

  5. The Values section at the bottom contains the possible values.

Value expression

The default value expression is defined as follows:

CODE
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()
  1. First, the expression checks if the context asset is an image.

  2. Next, the expression checks if values for height and width exist.

  3. 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:

  1. In the censhare Admin Client, open the Master data/Features table.

  2. Search for the Image orientation feature (ID: censhare:image-orientation).

  3. Select the feature, and click an icon to duplicate it.

  4. Fill out the required fields. Do not change the value type!

  5. In the Value expression field, paste the custom JavaScript according to your purposes.

  6. Edit the value list to match the custom values that are assigned in JavaScript.

  7. Click OK to save.

  8. 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 cropping - transformation variant.

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):

CODE
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, Image Transformation Variants.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.