How to create image varieties using a trigger

Learn 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.

Prerequisites

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

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

Creating 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. 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. Leave the Trigger view open and move to the next section to configure the trigger events, conditions and actions.

Configuring 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. Click Save.

  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. Click 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. Set the Variety Name to "mobile" in the Create Image Variety section.

    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. Click Save to save the image variety settings.

  4. On the Details screen, click 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 the Image Varieties to create tablet and desktop variants by adding more "Create Image Variety" actions to the same trigger.

© 2015- Squiz Pty Ltd