Skip to main content

Conditional Statements

As a developer you might want to apply transformations only after certain conditions are met. For example the use case could be like, you want to change the width of the image to 400px if the aspect ratio is less than 1. Then url would like - https://img.perceptpixel.com/demo-brjexrkh/if_ar_lt_1.0/w_400/if_end/example-5.jpeg

Original Image
example

Aspect ratio less than condition

You can set the target condition by using if_ar_lt_ prefix transformation literal following the required aspect ratio and closing the condition by if_end.

  • For now, we only support less than condition for only aspect ratio.
  • Aspect ratio can be in a Float number.
  • It supports chained transformation.

1. Rotate image if aspect ratio is less than 1

Rotate if AR < 1
example
https://img.perceptpixel.com/demo-brjexrkh/if_ar_lt_1.0/a_90/if_end/example-5.jpeg

2. Resize image if aspect ratio is less than 1

Resize if AR < 1
example
https://img.perceptpixel.com/demo-brjexrkh/if_ar_lt_1.0/w_400,h_200,c_pad/if_end/example-5.jpeg

3. Failing condition

Here the condition is not meant as Aspect ratio is greater than 0.5 thus no transformation is applied on the image.

Failed condition
example
URL - https://img.perceptpixel.com/demo-brjexrkh/if_ar_lt_0.5/w_400,h_200,c_pad/if_end/example-5.jpeg