Documentation Index

Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt

Use this file to discover all available pages before exploring further.

Image & Video APIs

Advanced conditional transformations

Last updated: Jun-09-2026

To apply a transformation only when a condition is met, you can embed a transformation directly within a condition in your URL or SDK call, using the format if_condition/transformation/if_end.

This page covers advanced techniques: combining multiple conditions with AND/OR logic, and defining fallback transformations using else branches.

For the basics of this syntax and worked examples, see Specifying transformations for a condition. For details on the conditions themselves, see Specifying conditions.

Multiple AND | OR conditions

You can specify multiple conditions to evaluate by joining the conditions with 'AND' or 'OR' conjunction operators.

Note
'AND' operators are evaluated before 'OR' operators.

For example, to crop the image to a width of 300 pixels and a height of 200 pixels, only if the aspect ratio is greater than 3:4, the width is greater than 300, and the height is greater than 200 (if_ar_gt_3:4_and_w_gt_300_and_h_gt_200):

Multiple conditions

Note
It's also possible to define multiple separate conditions, each with its own transformation result by using multiple if...end_if chained components in the URL.

Else branch transformations

You can specify a transformation that is applied in the case that the initial condition is evaluated as false (and hence the transformations associated with the condition are not applied), by using the if_else parameter to specify this fallback transformation.

For example, images with an original width less than or equal to 400px scale to fill a 240x120px container (if_iw_lte_400/c_fill,h_120,w_240), while images with an original width larger than 400px scale to fill a 240x400px container (if_else/c_fill,h_240,w_400):

Else conditions

 

In cases where the if condition is not in the preceding transformation component, then the if_else parameter also acts as an if_end parameter: all chained transformation components until the one with if_else are only applied if the previous condition holds true. Multiple conditional transformations can also be applied by adding an if_end parameter to the last transformation component in the chain, and to avoid ambiguity, the component with the if_else parameter should not have additional transformation instructions.

For example, if the width is less than or equal to 400 pixels then fill the image to 220x180 and add a red effect, else if the width is greater than 400 pixels then fill the image to 190x300 and add an oil painting effect:

Multiple else branch conditions

Advanced conditional transformation examples

  • Conditional cropping mode based on illustration score: This example ensures that uploaded graphics such as logos are never cut off, even if the art design significantly changes the required aspect ratio of the delivered image. Using the same transformation, photos scale and crop to completely fill the full space available.

    Using the ils conditional characteristic for both URLs below, Cloudinary resizes the cloudinary_icon_blue logo to the required portrait size using the pad method, and resizes the flower_shop photo to the same aspect ratio using the fill method:

    icon with conditional pad cropping
    photo with conditional fill cropping

Related topics

✔️ Feedback sent!

Rate this page:

one star two stars three stars four stars five stars