Rotate image (Event action)

Event action – Abstract

Purpose: Creates a target image rotated by multiples of 90° clockwise or counter-clockwise from an original image in the same file format.


NOTEThis event action is only available, if the functional extension module "Document Management" is installed and licensed.


See also: Rotate image (in forms)

The Rotate image (Event action) creates a target image in the same file format, rotated clockwise or counter-clockwise by multiples of 90°, starting from an original image.

The file formats JPEG, PNG, BMP and GIF are supported.

NOTE◄ Depending on the graphic format, compressed image data may be unpacked for rotation and then compressed again. Since the compression for the target data does not have to match the compression of the original data, the amount of data in the image may change. Even with a rotation of 0° or 360°, this can cause the image information to deviate from the original.

Configuration

The Angle parameter requires negative or positive integers, rounded to multiples of 90, to indicate the angle of rotation to be applied:

  • Positive values (>45°) define a clockwise rotation.

  • Negative values (<-45°) define a counter-clockwise rotation.

  • For example, a rotation angle of -90° is equivalent to a rotation angle of 270°.

The Input image parameter must provide the original image via a value resolver whose return value corresponds to the 'action event content' or 'byte array' type.

The Result image parameter defines where the target image should be saved to. The value resolver must define a suitable 'recipient' here (e.g. a variable or an object field) for a 'byte array' or the 'action event content' type.

images/download/attachments/177907546/image-2024-8-12_9-47-39-version-1-modificationdate-1723448858727-api-v2.png

NOTE◄ Often the original image is available as an uploaded file and the target image should also be saved as a new file or overwrite the original file. Then a File reference value resolver can be used for the Input image and Result image value resolvers respectively, which enables read and write operations in the server-side file system.

images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/warning.svg CAUTIONimages/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/warning.svg If a File reference value resolver is used for the Result image parameter, this requires a write access in the file system by which existing files can be overwritten or deleted without query.
This is particularly critical, since corresponding write accesses to the file system are executed without restriction even in test mode.

images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/warning.svg CAUTIONimages/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/warning.svg If the return value of the parameter Input image content is provided in an unsuitable file format, 'No value' (null) is output as the target image.
In conjunction with a file reference value resolver for the Result image parameter, the referenced file is then deleted!
In contrast to this, an assignment of null, e.g. to the documentContent field of a document (see Documents), simply has no effect.

Example

With the Change profile picture function, benutzer can define a personal 'profile picture', the so-called 'avatar', for the context of Lobster Data Platform / Orchestration, which can be edited a little with regard to zoom level and rotation directly after uploading.

Subsequent changes for an already uploaded profile picture, on the other hand, are not provided for by default. To demonstrate the Rotate image (Event action) event action, a function is set up to rotate the already uploaded profile image for an existing user account. For this purpose, two buttons are provided in the Users overview of the ribbon, which rotate the respective profile picture by 90° to the left or right in combination with a single selection for a user account.

Runtime example:

images/download/attachments/177907546/image2021-5-18_18-21-37-version-1-modificationdate-1723110202239-api-v2.png

  • These two buttons are intended to allow the 'Avatar' to be rotated to the left or right when a specific user is selected.

Configuration:

For each of the two menu commands an Custom action event is set up, which is to be triggered by the respective button (see Ribbon macros or Available commands/'Custom action event').

A common event handling for the two Triggering events 'Rotate Left' (ROTATE_LEFT) and 'Rotate Right' (ROTATE_RIGHT) is created and configured as shown on the right:

  • The Validating rule uses Check type to ensure that a 'user' account is present as an input object in the data context of event handling.

    NOTE◄ Here, the field avatarURL could additionally be checked for 'not empty' with an Entity property rule to ensure that a profile picture was uploaded for this user at all.


The Actions on passed rule is passed are first presented here in an overview. Details per action follow below:

  • A Set value event action defines the file path where the user's profile picture can be found as the value of the variable avatarFilePath.

  • Within an If then else event action, the variable rotation is assigned the desired rotation angle (-90° for left rotation, 90° for right rotation).

  • Finally, the event action Rotate image (Event action) follows:

    • The value for the Angle parameter is taken directly from the variable rotation .

    • For the Input image and Result image parameters, the text value from the avatarFilePath variable is used as the File path in a File reference value resolver in each case. The read access for the Input image and the write access for the Result image here exceptionally concern the same file. This is therefore overwritten when a rotation is executed.

NOTE◄ By default, the profile picture does not appear to be visible in the details for the selected user account. The rotated image will not appear until the next time the user in question logs in. Even if the profile picture of the logged-in user is rotated, it does not appear immediately in the top left corner of the user area of the menu bar in the existing session.

NOTE◄ The rotation overwrites the file referenced in the user account. Nothing changes in the reference in the user account. In this respect, the change takes effect without saving the user account.

images/download/attachments/177907546/image-2024-8-12_9-51-26-version-1-modificationdate-1723449086094-api-v2.png images/download/attachments/177907546/image-2024-8-12_9-54-5-version-1-modificationdate-1723449245103-api-v2.png

Configuration details:

The first Set value event action assigns the file path to the profile picture of the user present as input object to the avatarFilePath variable:

  • The avatarURL Object property contains a URL that points to the user's profile picture, if one is currently uploaded. Since a relative file path for the server's file system is required instead of the URL, the URL is prepared in two steps by concatenated Replace text value resolvers.

    • First, the img:// prefix is replaced with the relative path to the server's public directory (in a default installation ./upload/web/).

    • After that, the parameter part of the URL introduced with a question mark is removed, which enables the Regular expression? option.

Runtime example:

avatarURL="img://avatar/user_avatar_101.png?c=1619013361517"

... results (correspondingly) ...

avatarFilePath="./upload/web/avatar/user_avatar_101.png"

images/download/attachments/177907546/image-2024-8-12_9-57-7-version-1-modificationdate-1723449426587-api-v2.png

The following case distinction per If then else event action shall define the rotation angle for either left or right rotation depending on the ribbon button pressed at runtime.

  • Within an Entity property rule, this is done by comparing the return value of the value resolver Triggering event with the value of the dynamic enumeration Custom action event (see Static values, 'Any dynamic enumeration'), which defines the 'Rotate Left' event.

  • IF is assumed when the Triggering event is determined as 'Rotate Left', then the variable rotation is assigned the value -90.

  • ELSE is assumed when the Triggering event is 'Rotate Right', since no other triggering events are defined for event handling. Then, without an explicit check (not expanded in the image), the variable rotation is assigned the value 90 for the clockwise rotation.

images/download/attachments/177907546/image-2024-8-12_10-0-55-version-1-modificationdate-1723449654743-api-v2.png