How to create image varieties using a trigger

This tutorial shows you how to set up a trigger that can automatically creates different image varieties when someone uploads an image asset in your Matrix system.

This type of automation is excellent when you want to have consistent image sizes for your content editors. Consistently sized images are also useful in areas such as content and listing templates where image size constraints are essential to consider.

Before you start

There are no knowledge prerequisites required to complete this how-to.

You must be a System Administrator to make changes to triggers.

Create the trigger

When you create a trigger, be clear when naming and describing what each trigger does. Over time you may set up hundreds of triggers, so having well-named triggers saves you time working out which one to change.

  1. In the asset tree, open System management  Trigger manager.

  2. Right-click and select New child  Trigger."

  3. Name the trigger "Create global image varieties."

    This trigger fires when an image is created anywhere in the system. The word "global" in the trigger title helps to make the intent of the trigger stand out in the trigger listing.
  4. Provide an (optional but recommended) summary of what this trigger does in the Description field. For example, "When an image is created anywhere in the system, create global image varieties."

  5. Set an (optional, but recommended) category of "Image varieties" in the Category field.

  6. Select Create to finish creating the basic trigger, then select Edit to open the trigger’s Details screen.

  7. You can now move to the next section to configure the trigger events, conditions and actions.

Configure the trigger

Triggers work by combining different settings within the following configuration groups:

  • Events

  • Conditions

  • Actions.

For this specific example, the trigger creates an image variety (action) when an asset type of image (condition) is created (event).

  1. Select Asset Created in the Events section.

    The "Asset Created" event applies to any asset created through the Admin interface, Edit+, or through an asset builder.

  2. Select the "Asset is of type" condition in the Conditions section.

  3. Select Save to load additional options for the selected condition.

  4. In the "Asset is of type" condition you just created, select Image to only target image asset types in the trigger.

    Because this is a global image variety trigger, you do not need to set a tree location condition. Tree location conditions are useful when you want to have more control over what varieties get created for images under certain locations of your system.
  5. In the Actions section, select the Create Image Variety option.

  6. Select Save to finish creating the trigger.

Configure the image variety

Now you have created the action, you can set what name and size the image varieties should be. For this how-to, create a mobile-friendly sized image with a maximum size of 320px in width.

  1. In the Create image variety section, set the Variety name to mobile.
    You can adjust the size of the variety later without having to change the variety name and the references to the name in your other assets.

  2. In the Constrain by field, select "Width" and set the value to 320 px.
    When you constrain by "width" the image height remains relative to the width.

  3. Select Save to save the image variety settings.

  4. On the Details screen, select Enable to activate the trigger.

Summary

You have now configured an image varieties trigger that applies to all image assets added from this point onwards in your Matrix system.

Using this how-to as a guide, you can extend image varieties to create tablet and desktop variants by adding more Create image variety actions to the same trigger.