Create image varieties conditionally in a trigger


#1

I’m using triggers to create image varieties for assets added to a folder. However, I don’t want to upscale the source image.

For example, assume I have two actions:

  1. create variety v1, with max width of 1280 px
  2. create variety v2, with max width of 1920 px

Now, if I upload file.png of 1280x720, two varieties are created - v1 and v2. But, the upscaling quality is poor and image v2 looks bad.

Can I add a condition in the trigger so that v2 is not created (or uses source dimensions)? I’d like the actions to be executed only if the image dimensions are bigger than the proposed new variety.
Matrix Version: 6.27.0


(Iain Simmons) #2

Hi @np81,

I think you could accomplish this with a Trigger Condition of Keyword value, something like %asset_attribute_width^gt:1920:true:false% and check that it is equal to true.

That would need to be a separate trigger to the other variety.

The other thing is that you’d need to also check which one to use wherever you plan to display them. In which case it might be easier to always generate them, but use those keywords to determine which one to display (example assumes you have an asset listing or similar):

%begin_asset_attribute_width^gt:1920%
  <img src="%image_v_v2_url%" alt="%asset_attribute_alt%" />
%else_begin_asset_attribute_width^gt:1280%
  <img src="%image_v_v1_url%" alt="%asset_attribute_alt%" />
%else_%
  <img src="%asset_url%" alt="%asset_attribute_alt%" />
%end_%

#3

Thanks @isimmons. Hadn’t considered using a ‘nested’ trigger call.
I’ve used similar code as yours on an asset listing, checking the variety_width against %image_width%.