Conditional video transformations

You can define conditional expressions and then apply video transformations only if the specified condition is met, and otherwise either deliver the original video as-is or apply an alternative transformation.

Conditional transformation overview

A conditional transformation is one that is performed on the asset only if a specified condition is met. There are a variety of condition options you can use:

Quick example

both of the videos below have the same conditional transformation applied: It checks if the video is wider than 400 pixels, and if so, overlays a thumbs-up icon at the top-right of the video. Since the first video is a full size HD video, it gets the icon. However, the second video is only 350 pixels wide, so it does not meet the condition and no icon is added.

Ruby:
Copy to clipboard
cl_video_tag("marmots", :transformation=>[
  {:if=>"w_gt_400"},
  {:overlay=>"thumbs-up-small"},
  {:width=>150, :crop=>"scale"},
  {:flags=>"layer_apply", :gravity=>"north_east", :x=>10, :y=>10},
  {:if=>"end"},
  {:width=>400, :crop=>"limit"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('marmots.mp4'))
  ->conditional(Conditional::ifCondition("width > 400",(new Transformation())
  ->overlay(Overlay::source(
  Source::image("thumbs-up-small")
  ->transformation((new Transformation())
  ->resize(Resize::scale()->width(150)))
  )
  ->position((new Position())
  ->gravity(
  Gravity::compass(
  Compass::northEast()))
->offsetX(10)
->offsetY(10))
  )))
  ->resize(Resize::limitFit()->width(400));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("marmots", array("transformation"=>array(
  array("if"=>"w_gt_400"),
  array("overlay"=>"thumbs-up-small"),
  array("width"=>150, "crop"=>"scale"),
  array("flags"=>"layer_apply", "gravity"=>"north_east", "x"=>10, "y"=>10),
  array("if"=>"end"),
  array("width"=>400, "crop"=>"limit")
  )))
Python:
Copy to clipboard
CloudinaryVideo("marmots").video(transformation=[
  {'if': "w_gt_400"},
  {'overlay': "thumbs-up-small"},
  {'width': 150, 'crop': "scale"},
  {'flags': "layer_apply", 'gravity': "north_east", 'x': 10, 'y': 10},
  {'if': "end"},
  {'width': 400, 'crop': "limit"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("marmots", {transformation: [
  {if: "w_gt_400"},
  {overlay: "thumbs-up-small"},
  {width: 150, crop: "scale"},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 10},
  {if: "end"},
  {width: 400, crop: "limit"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .if("w_gt_400").chain()
  .overlay(new Layer().publicId("thumbs-up-small")).chain()
  .width(150).crop("scale").chain()
  .flags("layer_apply").gravity("north_east").x(10).y(10).chain()
  .if("end").chain()
  .width(400).crop("limit")).videoTag("marmots");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryVideo("marmots.mp4")
  .conditional(
    ifCondition(
      "width > 400",
      new MediaTransformation().overlay(
        source(
          image("thumbs-up-small").transformation(
            new MediaTransformation().resize(scale().width(150))
          )
        ).position(
          new Position().gravity(compass("north_east")).offsetX(10).offsetY(10)
        )
      )
    )
  )
  .resize(limitFit().width(400));
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('marmots', {transformation: [
  {if: "w_gt_400"},
  {overlay: new cloudinary.Layer().publicId("thumbs-up-small")},
  {width: 150, crop: "scale"},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 10},
  {if: "end"},
  {width: 400, crop: "limit"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("marmots", {transformation: [
  {if: "w_gt_400"},
  {overlay: new cloudinary.Layer().publicId("thumbs-up-small")},
  {width: 150, crop: "scale"},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 10},
  {if: "end"},
  {width: 400, crop: "limit"}
  ]})
React:
Copy to clipboard
<Video publicId="marmots" >
  <Transformation if="w_gt_400" />
  <Transformation overlay="thumbs-up-small" />
  <Transformation width="150" crop="scale" />
  <Transformation flags="layer_apply" gravity="north_east" x="10" y="10" />
  <Transformation if="end" />
  <Transformation width="400" crop="limit" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="marmots" >
  <cld-transformation if="w_gt_400" />
  <cld-transformation :overlay="thumbs-up-small" />
  <cld-transformation width="150" crop="scale" />
  <cld-transformation flags="layer_apply" gravity="north_east" x="10" y="10" />
  <cld-transformation if="end" />
  <cld-transformation width="400" crop="limit" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="marmots" >
  <cl-transformation if="w_gt_400">
  </cl-transformation>
  <cl-transformation overlay="thumbs-up-small">
  </cl-transformation>
  <cl-transformation width="150" crop="scale">
  </cl-transformation>
  <cl-transformation flags="layer_apply" gravity="north_east" x="10" y="10">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
  <cl-transformation width="400" crop="limit">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .If("w_gt_400").Chain()
  .Overlay(new Layer().PublicId("thumbs-up-small")).Chain()
  .Width(150).Crop("scale").Chain()
  .Flags("layer_apply").Gravity("north_east").X(10).Y(10).Chain()
  .If("end").Chain()
  .Width(400).Crop("limit")).BuildVideoTag("marmots")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setIf("w_gt_400").chain()
  .setOverlay("thumbs-up-small").chain()
  .setWidth(150).setCrop("scale").chain()
  .setFlags("layer_apply").setGravity("north_east").setX(10).setY(10).chain()
  .setIf("end").chain()
  .setWidth(400).setCrop("limit")).generate("marmots.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .if("w_gt_400").chain()
  .overlay(new Layer().publicId("thumbs-up-small")).chain()
  .width(150).crop("scale").chain()
  .flags("layer_apply").gravity("north_east").x(10).y(10).chain()
  .if("end").chain()
  .width(400).crop("limit")).resourceType("video").generate("marmots.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.

Ruby:
Copy to clipboard
cl_video_tag("docs/pencil_sketch_sm", :transformation=>[
  {:if=>"w_gt_400"},
  {:overlay=>"thumbs-up-small"},
  {:width=>150, :crop=>"scale"},
  {:flags=>"layer_apply", :gravity=>"north_east", :x=>10, :y=>10},
  {:if=>"end"},
  {:width=>400, :crop=>"limit"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('docs/pencil_sketch_sm.mp4'))
  ->conditional(Conditional::ifCondition("width > 400",(new Transformation())
  ->overlay(Overlay::source(
  Source::image("thumbs-up-small")
  ->transformation((new Transformation())
  ->resize(Resize::scale()->width(150)))
  )
  ->position((new Position())
  ->gravity(
  Gravity::compass(
  Compass::northEast()))
->offsetX(10)
->offsetY(10))
  )))
  ->resize(Resize::limitFit()->width(400));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("docs/pencil_sketch_sm", array("transformation"=>array(
  array("if"=>"w_gt_400"),
  array("overlay"=>"thumbs-up-small"),
  array("width"=>150, "crop"=>"scale"),
  array("flags"=>"layer_apply", "gravity"=>"north_east", "x"=>10, "y"=>10),
  array("if"=>"end"),
  array("width"=>400, "crop"=>"limit")
  )))
Python:
Copy to clipboard
CloudinaryVideo("docs/pencil_sketch_sm").video(transformation=[
  {'if': "w_gt_400"},
  {'overlay': "thumbs-up-small"},
  {'width': 150, 'crop': "scale"},
  {'flags': "layer_apply", 'gravity': "north_east", 'x': 10, 'y': 10},
  {'if': "end"},
  {'width': 400, 'crop': "limit"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("docs/pencil_sketch_sm", {transformation: [
  {if: "w_gt_400"},
  {overlay: "thumbs-up-small"},
  {width: 150, crop: "scale"},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 10},
  {if: "end"},
  {width: 400, crop: "limit"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .if("w_gt_400").chain()
  .overlay(new Layer().publicId("thumbs-up-small")).chain()
  .width(150).crop("scale").chain()
  .flags("layer_apply").gravity("north_east").x(10).y(10).chain()
  .if("end").chain()
  .width(400).crop("limit")).videoTag("docs/pencil_sketch_sm");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryVideo("docs/pencil_sketch_sm.mp4")
  .conditional(
    ifCondition(
      "width > 400",
      new MediaTransformation().overlay(
        source(
          image("thumbs-up-small").transformation(
            new MediaTransformation().resize(scale().width(150))
          )
        ).position(
          new Position().gravity(compass("north_east")).offsetX(10).offsetY(10)
        )
      )
    )
  )
  .resize(limitFit().width(400));
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('docs/pencil_sketch_sm', {transformation: [
  {if: "w_gt_400"},
  {overlay: new cloudinary.Layer().publicId("thumbs-up-small")},
  {width: 150, crop: "scale"},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 10},
  {if: "end"},
  {width: 400, crop: "limit"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("docs/pencil_sketch_sm", {transformation: [
  {if: "w_gt_400"},
  {overlay: new cloudinary.Layer().publicId("thumbs-up-small")},
  {width: 150, crop: "scale"},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 10},
  {if: "end"},
  {width: 400, crop: "limit"}
  ]})
React:
Copy to clipboard
<Video publicId="docs/pencil_sketch_sm" >
  <Transformation if="w_gt_400" />
  <Transformation overlay="thumbs-up-small" />
  <Transformation width="150" crop="scale" />
  <Transformation flags="layer_apply" gravity="north_east" x="10" y="10" />
  <Transformation if="end" />
  <Transformation width="400" crop="limit" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="docs/pencil_sketch_sm" >
  <cld-transformation if="w_gt_400" />
  <cld-transformation :overlay="thumbs-up-small" />
  <cld-transformation width="150" crop="scale" />
  <cld-transformation flags="layer_apply" gravity="north_east" x="10" y="10" />
  <cld-transformation if="end" />
  <cld-transformation width="400" crop="limit" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="docs/pencil_sketch_sm" >
  <cl-transformation if="w_gt_400">
  </cl-transformation>
  <cl-transformation overlay="thumbs-up-small">
  </cl-transformation>
  <cl-transformation width="150" crop="scale">
  </cl-transformation>
  <cl-transformation flags="layer_apply" gravity="north_east" x="10" y="10">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
  <cl-transformation width="400" crop="limit">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .If("w_gt_400").Chain()
  .Overlay(new Layer().PublicId("thumbs-up-small")).Chain()
  .Width(150).Crop("scale").Chain()
  .Flags("layer_apply").Gravity("north_east").X(10).Y(10).Chain()
  .If("end").Chain()
  .Width(400).Crop("limit")).BuildVideoTag("docs/pencil_sketch_sm")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setIf("w_gt_400").chain()
  .setOverlay("thumbs-up-small").chain()
  .setWidth(150).setCrop("scale").chain()
  .setFlags("layer_apply").setGravity("north_east").setX(10).setY(10).chain()
  .setIf("end").chain()
  .setWidth(400).setCrop("limit")).generate("docs/pencil_sketch_sm.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .if("w_gt_400").chain()
  .overlay(new Layer().publicId("thumbs-up-small")).chain()
  .width(150).crop("scale").chain()
  .flags("layer_apply").gravity("north_east").x(10).y(10).chain()
  .if("end").chain()
  .width(400).crop("limit")).resourceType("video").generate("docs/pencil_sketch_sm.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.

Specifying video conditions

To specify a condition to be met before applying a transformation, use the if parameter (also if in URLs). The if parameter accepts a string value detailing the condition to evaluate, and is specified in the URL in the following format:

if_<video characteristic>_<operator>_<video characteristic value>

Where:

  • video characteristic: The video parameter representing the characteristic to evaluate, for example w (or width in SDKs).
  • operator: The comparison operator for the comparison, for example lt for 'less than' (or < in SDKs).
  • video characteristic value: A hard coded value to check against, a supported user-defined variable containing a value to check against, or a different video characteristic you want to compare to.

    For example, if you only want to apply a transformation to non-square videos, you could check if the width characteristic of your video is not equal to its height characteristic: if_w_ne_h

Tips

  • Specify strings for a characteristic sub-element or value surrounded by ! !. For example, if_ if_ctx:!productType!_eq_!shoes!.
  • You can check whether a string characteristic currently has no value using !!.
    For example: if some-condition_eq_!!

Supported video condition parameters

Characteristic Description
w (also width in SDKs) The asset's current width.
iw The asset's initial width.
h (also height in SDKs) The asset's current height.
ih The asset's initial height.
ar (also aspect_ratio in SDKs) The aspect ratio of the asset. The compared value can be either decimal (e.g., 1.5) or a ratio (e.g., 3:4).
iar The asset's initial aspect ratio.
ctx A contextual metadata value assigned to an asset.
md A structured metadata value assigned to an asset.
tags The set of tags assigned to the asset.
du (also duration in SDKs) The current duration of the video.
idu The video's initial duration.

Supported comparison operators

URL SDK symbol Description
eq = Equal to
ne != Not equal to
lt < Less than
gt > Greater than
lte <= Less than or equal to
gte >= Greater than or equal to
in|nin in|nin Included in | Not included in

Compares a set of strings against another set of strings. See Using the in and nin operators for examples.

When working with the Cloudinary SDKs, you can specify the condition using the SDK characteristic names and operator symbols, or you can specify it using the URL format. For example, both of the following are valid:

  • { if: "w_gt_1000"},...
  • { if: "width > 1000"},...

Using the in and nin operators

The in and nin operators compare two sets of strings. The : delimiter between strings denotes AND. String sets can include tags, contextual metadata or structured metadata values, for example:

  • To determine if sale and in_stock are present in the tags of a particular asset, use:
    if_!sale:in_stock!_in_tags.
  • To determine if the key named color exists in the contextual metadata of a particular asset, use:
    if_!color!_in_ctx.
  • To determine if a structured metadata field with external ID, color-id, has been set for a particular asset, use:
    if_!color-id!_in_md.
  • To determine if a list value with external ID, green-id, has been selected from a multiple-selection structured metadata field with external ID, colors-id, for a particular asset, use:
    if_!green-id!_in_md!colors-id!.

Supported conditional video transformation parameters and flags

  • All video transformation parameters can be assigned in conditions except:

    • You cannot assign transformation parameters for the format, fetch_format, color_space, delay, video_codec, audio_codec, start_offset, end_offset, or duration parameters.
    • The angle parameter cannot be set to ignore.
  • Only the following flags are supported inside conditional video transformations:
    layer_apply, relative, attachment, awebp

Notes

  • For the w, h, and ar parameters, the values refer to the current video status in the transformation chain (i.e., if transformations have already been applied to the video), while iw, ih, iar always refer to the original video.
  • dpr is not supported as a conditional transformation with the ar characteristic. Additionally, w and h are supported with dpr as long as they are still equal to iw or ih when the condition is evaluated. If dpr is specified in the transformation as a whole, and one of the conditional branches includes a resizing transformation, you need to specify a resize transformation in all the other branches too.
  • The ar (aspect ratio) parameter should be compared using 'greater than' or 'less than' rather than with 'equals'. This is because the width and height values are given as integers and not floating point values, leading to an "almost exact" calculated aspect ratio.

Specifying transformations for a condition

The transformation for a condition should be specified between the condition component and an if_end component in the format:

if_condition/transformation/if_end

For example:

f_ar_lt_1.0/b_darkorange,c_pad,h_300,w_500/if_end

In the following transformation, both videos are are scaled to a width of 500px. Afterwards, the same conditional padded-resize transformation shown above is applied to both videos. However, since the condition applies only for portrait videos (those with an aspect ratio less than 1.0) the resizing and padding is only applied to the parrot video.

Ruby:
Copy to clipboard
cl_video_tag("rafting", :transformation=>[
  {:width=>500, :crop=>"scale"},
  {:if=>"ar_lt_1.0"},
  {:background=>"darkorange", :height=>300, :width=>500, :crop=>"pad"},
  {:if=>"end"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('rafting.mp4'))
  ->resize(Resize::scale()->width(500))
  ->conditional(Conditional::ifCondition("aspect_ratio < 1.0",(new Transformation())
  ->resize(Resize::pad()->width(500)
->height(300)
  ->background(
  Background::color(Color::DARKORANGE))
  )));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("rafting", array("transformation"=>array(
  array("width"=>500, "crop"=>"scale"),
  array("if"=>"ar_lt_1.0"),
  array("background"=>"darkorange", "height"=>300, "width"=>500, "crop"=>"pad"),
  array("if"=>"end")
  )))
Python:
Copy to clipboard
CloudinaryVideo("rafting").video(transformation=[
  {'width': 500, 'crop': "scale"},
  {'if': "ar_lt_1.0"},
  {'background': "darkorange", 'height': 300, 'width': 500, 'crop': "pad"},
  {'if': "end"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("rafting", {transformation: [
  {width: 500, crop: "scale"},
  {if: "ar_lt_1.0"},
  {background: "darkorange", height: 300, width: 500, crop: "pad"},
  {if: "end"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .if("ar_lt_1.0").chain()
  .background("darkorange").height(300).width(500).crop("pad").chain()
  .if("end")).videoTag("rafting");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryVideo("rafting.mp4")
  .resize(scale().width(500))
  .conditional(
    ifCondition(
      "aspect_ratio < 1.0",
      new MediaTransformation().resize(
        pad().width(500).height(300).background(color("darkorange"))
      )
    )
  );
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('rafting', {transformation: [
  {width: 500, crop: "scale"},
  {if: "ar_lt_1.0"},
  {background: "darkorange", height: 300, width: 500, crop: "pad"},
  {if: "end"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("rafting", {transformation: [
  {width: 500, crop: "scale"},
  {if: "ar_lt_1.0"},
  {background: "darkorange", height: 300, width: 500, crop: "pad"},
  {if: "end"}
  ]})
React:
Copy to clipboard
<Video publicId="rafting" >
  <Transformation width="500" crop="scale" />
  <Transformation if="ar_lt_1.0" />
  <Transformation background="darkorange" height="300" width="500" crop="pad" />
  <Transformation if="end" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="rafting" >
  <cld-transformation width="500" crop="scale" />
  <cld-transformation if="ar_lt_1.0" />
  <cld-transformation background="darkorange" height="300" width="500" crop="pad" />
  <cld-transformation if="end" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="rafting" >
  <cl-transformation width="500" crop="scale">
  </cl-transformation>
  <cl-transformation if="ar_lt_1.0">
  </cl-transformation>
  <cl-transformation background="darkorange" height="300" width="500" crop="pad">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(500).Crop("scale").Chain()
  .If("ar_lt_1.0").Chain()
  .Background("darkorange").Height(300).Width(500).Crop("pad").Chain()
  .If("end")).BuildVideoTag("rafting")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(500).setCrop("scale").chain()
  .setIf("ar_lt_1.0").chain()
  .setBackground("darkorange").setHeight(300).setWidth(500).setCrop("pad").chain()
  .setIf("end")).generate("rafting.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .if("ar_lt_1.0").chain()
  .background("darkorange").height(300).width(500).crop("pad").chain()
  .if("end")).resourceType("video").generate("rafting.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.
Ruby:
Copy to clipboard
cl_video_tag("docs/parrot", :transformation=>[
  {:width=>500, :crop=>"scale"},
  {:if=>"ar_lt_1.0"},
  {:background=>"darkorange", :height=>300, :width=>500, :crop=>"pad"},
  {:if=>"end"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('docs/parrot.mp4'))
  ->resize(Resize::scale()->width(500))
  ->conditional(Conditional::ifCondition("aspect_ratio < 1.0",(new Transformation())
  ->resize(Resize::pad()->width(500)
->height(300)
  ->background(
  Background::color(Color::DARKORANGE))
  )));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("docs/parrot", array("transformation"=>array(
  array("width"=>500, "crop"=>"scale"),
  array("if"=>"ar_lt_1.0"),
  array("background"=>"darkorange", "height"=>300, "width"=>500, "crop"=>"pad"),
  array("if"=>"end")
  )))
Python:
Copy to clipboard
CloudinaryVideo("docs/parrot").video(transformation=[
  {'width': 500, 'crop': "scale"},
  {'if': "ar_lt_1.0"},
  {'background': "darkorange", 'height': 300, 'width': 500, 'crop': "pad"},
  {'if': "end"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("docs/parrot", {transformation: [
  {width: 500, crop: "scale"},
  {if: "ar_lt_1.0"},
  {background: "darkorange", height: 300, width: 500, crop: "pad"},
  {if: "end"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .if("ar_lt_1.0").chain()
  .background("darkorange").height(300).width(500).crop("pad").chain()
  .if("end")).videoTag("docs/parrot");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryVideo("docs/parrot.mp4")
  .resize(scale().width(500))
  .conditional(
    ifCondition(
      "aspect_ratio < 1.0",
      new MediaTransformation().resize(
        pad().width(500).height(300).background(color("darkorange"))
      )
    )
  );
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('docs/parrot', {transformation: [
  {width: 500, crop: "scale"},
  {if: "ar_lt_1.0"},
  {background: "darkorange", height: 300, width: 500, crop: "pad"},
  {if: "end"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("docs/parrot", {transformation: [
  {width: 500, crop: "scale"},
  {if: "ar_lt_1.0"},
  {background: "darkorange", height: 300, width: 500, crop: "pad"},
  {if: "end"}
  ]})
React:
Copy to clipboard
<Video publicId="docs/parrot" >
  <Transformation width="500" crop="scale" />
  <Transformation if="ar_lt_1.0" />
  <Transformation background="darkorange" height="300" width="500" crop="pad" />
  <Transformation if="end" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="docs/parrot" >
  <cld-transformation width="500" crop="scale" />
  <cld-transformation if="ar_lt_1.0" />
  <cld-transformation background="darkorange" height="300" width="500" crop="pad" />
  <cld-transformation if="end" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="docs/parrot" >
  <cl-transformation width="500" crop="scale">
  </cl-transformation>
  <cl-transformation if="ar_lt_1.0">
  </cl-transformation>
  <cl-transformation background="darkorange" height="300" width="500" crop="pad">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(500).Crop("scale").Chain()
  .If("ar_lt_1.0").Chain()
  .Background("darkorange").Height(300).Width(500).Crop("pad").Chain()
  .If("end")).BuildVideoTag("docs/parrot")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(500).setCrop("scale").chain()
  .setIf("ar_lt_1.0").chain()
  .setBackground("darkorange").setHeight(300).setWidth(500).setCrop("pad").chain()
  .setIf("end")).generate("docs/parrot.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .if("ar_lt_1.0").chain()
  .background("darkorange").height(300).width(500).crop("pad").chain()
  .if("end")).resourceType("video").generate("docs/parrot.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.

Note

Transformation URLs technically support defining both the condition and a single resulting transformation inside a single transformation component (without the need for a closing end_if). However, to avoid ambiguity, the best practice is to always use if and if_end components in your URL as shown above.

  • Some SDKs require this separation and automatically generate URLs in the if...end_if format.
  • Named transformation cannot be placed in the same transformation component as its condition (e.g., if_w_eq_h,t_trans is not supported) and must be specified using the if...if_end format.
  • If you do include both the if condition and the resulting transformation parameters within a single component of the URL, the if condition is evaluated first, regardless of it's location within the component and (only) when the condition is true, all transformation parameters specified in that component are applied.

IF > THEN with chained transformations

You can apply multiple chained transformations to your condition by including the entire chained transformation in between the if and if_end components, as follows:

if_<video parameter>_<operator>_<value>/<If true transformation1>/<If true chained transformation2>/<if_end>

You can optionally add additional transformations after the if_end to apply additional transformations to the result of the conditional transformation.

However, you cannot append another conditional transformation after the end_if, nor can you nest If conditions.

The example below checks whether the video asset's tags include a 'cloudinary' tag. Only in that case, a chained transformation including an image overlay (Cloudinary logo) and a text overlay ('By Cloudinary') are applied. If 'cloudinary' is not one of the tags, no image or text overlay is applied.

Note that this example also includes a scale-down transformation before the beginning of the conditional transformation and a duration trim after the end of the conditional transformation. Those transformations are applied regardless of the true or false result of the condition.

Ruby:
Copy to clipboard
cl_video_tag("snow_horses", :transformation=>[
  {:width=>500, :crop=>"scale"},
  {:if=>"!cloudinary!_in_tags"},
  {:overlay=>"cloudinary_icon_white"},
  {:width=>100, :crop=>"scale"},
  {:opacity=>50},
  {:effect=>"brightness:100"},
  {:flags=>"layer_apply", :gravity=>"north_east"},
  {:overlay=>{:font_family=>"arial", :font_size=>15, :text=>"By%2520Cloudinary"}},
  {:flags=>"layer_apply", :gravity=>"north_east", :x=>10, :y=>80},
  {:if=>"end"},
  {:duration=>"5.0"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('snow_horses.mp4'))
  ->resize(Resize::scale()->width(500))
  ->conditional(Conditional::ifCondition("!cloudinary! in tags",(new Transformation())
  ->overlay(Overlay::source(
  Source::image("cloudinary_icon_white")
  ->transformation((new Transformation())
  ->resize(Resize::scale()->width(100))
  ->adjust(Adjust::opacity(50))
  ->adjust(Adjust::brightness()->level(100)))
  )
  ->position((new Position())
  ->gravity(
  Gravity::compass(
  Compass::northEast()))
  )
  )
  ->overlay(Overlay::source(
  Source::text("By%20Cloudinary",(new TextStyle("arial",15))))
  ->position((new Position())
  ->gravity(
  Gravity::compass(
  Compass::northEast()))
->offsetX(10)
->offsetY(80))
  )))
  ->videoEdit(VideoEdit::trim()->duration(5.0));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("snow_horses", array("transformation"=>array(
  array("width"=>500, "crop"=>"scale"),
  array("if"=>"!cloudinary!_in_tags"),
  array("overlay"=>"cloudinary_icon_white"),
  array("width"=>100, "crop"=>"scale"),
  array("opacity"=>50),
  array("effect"=>"brightness:100"),
  array("flags"=>"layer_apply", "gravity"=>"north_east"),
  array("overlay"=>array("font_family"=>"arial", "font_size"=>15, "text"=>"By%2520Cloudinary")),
  array("flags"=>"layer_apply", "gravity"=>"north_east", "x"=>10, "y"=>80),
  array("if"=>"end"),
  array("duration"=>"5.0")
  )))
Python:
Copy to clipboard
CloudinaryVideo("snow_horses").video(transformation=[
  {'width': 500, 'crop': "scale"},
  {'if': "!cloudinary!_in_tags"},
  {'overlay': "cloudinary_icon_white"},
  {'width': 100, 'crop': "scale"},
  {'opacity': 50},
  {'effect': "brightness:100"},
  {'flags': "layer_apply", 'gravity': "north_east"},
  {'overlay': {'font_family': "arial", 'font_size': 15, 'text': "By%2520Cloudinary"}},
  {'flags': "layer_apply", 'gravity': "north_east", 'x': 10, 'y': 80},
  {'if': "end"},
  {'duration': "5.0"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("snow_horses", {transformation: [
  {width: 500, crop: "scale"},
  {if: "!cloudinary!_in_tags"},
  {overlay: "cloudinary_icon_white"},
  {width: 100, crop: "scale"},
  {opacity: 50},
  {effect: "brightness:100"},
  {flags: "layer_apply", gravity: "north_east"},
  {overlay: {font_family: "arial", font_size: 15, text: "By%2520Cloudinary"}},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 80},
  {if: "end"},
  {duration: "5.0"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .if("!cloudinary!_in_tags").chain()
  .overlay(new Layer().publicId("cloudinary_icon_white")).chain()
  .width(100).crop("scale").chain()
  .opacity(50).chain()
  .effect("brightness:100").chain()
  .flags("layer_apply").gravity("north_east").chain()
  .overlay(new TextLayer().fontFamily("arial").fontSize(15).text("By%2520Cloudinary")).chain()
  .flags("layer_apply").gravity("north_east").x(10).y(80).chain()
  .if("end").chain()
  .duration("5.0")).videoTag("snow_horses");
JS (js-url-gen v1.x):
Copy to clipboard
// This code example is not currently available.
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('snow_horses', {transformation: [
  {width: 500, crop: "scale"},
  {if: "!cloudinary!_in_tags"},
  {overlay: new cloudinary.Layer().publicId("cloudinary_icon_white")},
  {width: 100, crop: "scale"},
  {opacity: 50},
  {effect: "brightness:100"},
  {flags: "layer_apply", gravity: "north_east"},
  {overlay: new cloudinary.TextLayer().fontFamily("arial").fontSize(15).text("By%2520Cloudinary")},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 80},
  {if: "end"},
  {duration: "5.0"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("snow_horses", {transformation: [
  {width: 500, crop: "scale"},
  {if: "!cloudinary!_in_tags"},
  {overlay: new cloudinary.Layer().publicId("cloudinary_icon_white")},
  {width: 100, crop: "scale"},
  {opacity: 50},
  {effect: "brightness:100"},
  {flags: "layer_apply", gravity: "north_east"},
  {overlay: new cloudinary.TextLayer().fontFamily("arial").fontSize(15).text("By%2520Cloudinary")},
  {flags: "layer_apply", gravity: "north_east", x: 10, y: 80},
  {if: "end"},
  {duration: "5.0"}
  ]})
React:
Copy to clipboard
<Video publicId="snow_horses" >
  <Transformation width="500" crop="scale" />
  <Transformation if="!cloudinary!_in_tags" />
  <Transformation overlay="cloudinary_icon_white" />
  <Transformation width="100" crop="scale" />
  <Transformation opacity="50" />
  <Transformation effect="brightness:100" />
  <Transformation flags="layer_apply" gravity="north_east" />
  <Transformation overlay={{fontFamily: "arial", fontSize: 15, text: "By%2520Cloudinary"}} />
  <Transformation flags="layer_apply" gravity="north_east" x="10" y="80" />
  <Transformation if="end" />
  <Transformation duration="5.0" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="snow_horses" >
  <cld-transformation width="500" crop="scale" />
  <cld-transformation if="!cloudinary!_in_tags" />
  <cld-transformation :overlay="cloudinary_icon_white" />
  <cld-transformation width="100" crop="scale" />
  <cld-transformation opacity="50" />
  <cld-transformation effect="brightness:100" />
  <cld-transformation flags="layer_apply" gravity="north_east" />
  <cld-transformation :overlay="{fontFamily: 'arial', fontSize: 15, text: 'By%2520Cloudinary'}" />
  <cld-transformation flags="layer_apply" gravity="north_east" x="10" y="80" />
  <cld-transformation if="end" />
  <cld-transformation duration="5.0" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="snow_horses" >
  <cl-transformation width="500" crop="scale">
  </cl-transformation>
  <cl-transformation if="!cloudinary!_in_tags">
  </cl-transformation>
  <cl-transformation overlay="cloudinary_icon_white">
  </cl-transformation>
  <cl-transformation width="100" crop="scale">
  </cl-transformation>
  <cl-transformation opacity="50">
  </cl-transformation>
  <cl-transformation effect="brightness:100">
  </cl-transformation>
  <cl-transformation flags="layer_apply" gravity="north_east">
  </cl-transformation>
  <cl-transformation overlay="text:arial_15:By%2520Cloudinary">
  </cl-transformation>
  <cl-transformation flags="layer_apply" gravity="north_east" x="10" y="80">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
  <cl-transformation duration="5.0">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(500).Crop("scale").Chain()
  .If("!cloudinary!_in_tags").Chain()
  .Overlay(new Layer().PublicId("cloudinary_icon_white")).Chain()
  .Width(100).Crop("scale").Chain()
  .Opacity(50).Chain()
  .Effect("brightness:100").Chain()
  .Flags("layer_apply").Gravity("north_east").Chain()
  .Overlay(new TextLayer().FontFamily("arial").FontSize(15).Text("By%2520Cloudinary")).Chain()
  .Flags("layer_apply").Gravity("north_east").X(10).Y(80).Chain()
  .If("end").Chain()
  .Duration("5.0")).BuildVideoTag("snow_horses")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(500).setCrop("scale").chain()
  .setIf("!cloudinary!_in_tags").chain()
  .setOverlay("cloudinary_icon_white").chain()
  .setWidth(100).setCrop("scale").chain()
  .setOpacity(50).chain()
  .setEffect("brightness:100").chain()
  .setFlags("layer_apply").setGravity("north_east").chain()
  .setOverlay("text:arial_15:By%2520Cloudinary").chain()
  .setFlags("layer_apply").setGravity("north_east").setX(10).setY(80).chain()
  .setIf("end").chain()
  .setDuration("5.0")).generate("snow_horses.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .if("!cloudinary!_in_tags").chain()
  .overlay(new Layer().publicId("cloudinary_icon_white")).chain()
  .width(100).crop("scale").chain()
  .opacity(50).chain()
  .effect("brightness:100").chain()
  .flags("layer_apply").gravity("north_east").chain()
  .overlay(new TextLayer().fontFamily("arial").fontSize(15).text("By%2520Cloudinary")).chain()
  .flags("layer_apply").gravity("north_east").x(10).y(80).chain()
  .if("end").chain()
  .duration("5.0")).resourceType("video").generate("snow_horses.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.

Notes

  • When your conditional transformation also includes an if_else branch, then the if_else component also behaves as an if_end, and therefore no if_end component is necessary.
  • When you use variable or conditional expressions that include the tags, ctx or md parameters, their values are exposed publicly in the URL. If you want to prevent such values from being exposed, you can disable the Usage of tags/context/metadata in transformation URLs option in the Security tab of your account settings (enabled by default). When this setting is disabled, any URL that exposes tags, contextual metadata or structured metadata values will return an error.

Multiple IF conditions with AND, OR

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.

The example below checks whether the video's aspect ratio is larger than a standard mobile portrait orientation AND if it has a large width. Only in this case, it crops the video to a portrait orientation with a width of 500. If the video already has a portrait orientation (condition 1 is false) or if the original width is less than 500 (condition 2 is false), the conditional transformation is ignored and the video is delivered in its original shape and size.

Ruby:
Copy to clipboard
cl_video_tag("snow_horses", :transformation=>[
  {:if=>"ar_gt_0.65_and_w_gt_500"},
  {:aspect_ratio=>"0.65", :width=>500, :crop=>"fill"},
  {:if=>"end"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('snow_horses.mp4'))
  ->conditional(Conditional::ifCondition("aspect_ratio > 0.65 && width > 500",(new Transformation())
  ->resize(Resize::fill()->width(500)
->aspectRatio(0.65))));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("snow_horses", array("transformation"=>array(
  array("if"=>"ar_gt_0.65_and_w_gt_500"),
  array("aspect_ratio"=>"0.65", "width"=>500, "crop"=>"fill"),
  array("if"=>"end")
  )))
Python:
Copy to clipboard
CloudinaryVideo("snow_horses").video(transformation=[
  {'if': "ar_gt_0.65_and_w_gt_500"},
  {'aspect_ratio': "0.65", 'width': 500, 'crop': "fill"},
  {'if': "end"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("snow_horses", {transformation: [
  {if: "ar_gt_0.65_and_w_gt_500"},
  {aspect_ratio: "0.65", width: 500, crop: "fill"},
  {if: "end"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .if("ar_gt_0.65_and_w_gt_500").chain()
  .aspectRatio("0.65").width(500).crop("fill").chain()
  .if("end")).videoTag("snow_horses");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryVideo("snow_horses.mp4").conditional(
  ifCondition(
    "aspect_ratio > 0.65 && width > 500",
    new MediaTransformation().resize(fill().width(500).aspectRatio(0.65))
  )
);
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('snow_horses', {transformation: [
  {if: "ar_gt_0.65_and_w_gt_500"},
  {aspectRatio: "0.65", width: 500, crop: "fill"},
  {if: "end"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("snow_horses", {transformation: [
  {if: "ar_gt_0.65_and_w_gt_500"},
  {aspect_ratio: "0.65", width: 500, crop: "fill"},
  {if: "end"}
  ]})
React:
Copy to clipboard
<Video publicId="snow_horses" >
  <Transformation if="ar_gt_0.65_and_w_gt_500" />
  <Transformation aspectRatio="0.65" width="500" crop="fill" />
  <Transformation if="end" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="snow_horses" >
  <cld-transformation if="ar_gt_0.65_and_w_gt_500" />
  <cld-transformation aspect-ratio="0.65" width="500" crop="fill" />
  <cld-transformation if="end" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="snow_horses" >
  <cl-transformation if="ar_gt_0.65_and_w_gt_500">
  </cl-transformation>
  <cl-transformation aspect-ratio="0.65" width="500" crop="fill">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .If("ar_gt_0.65_and_w_gt_500").Chain()
  .AspectRatio("0.65").Width(500).Crop("fill").Chain()
  .If("end")).BuildVideoTag("snow_horses")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setIf("ar_gt_0.65_and_w_gt_500").chain()
  .setAspectRatio("0.65").setWidth(500).setCrop("fill").chain()
  .setIf("end")).generate("snow_horses.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .if("ar_gt_0.65_and_w_gt_500").chain()
  .aspectRatio("0.65").width(500).crop("fill").chain()
  .if("end")).resourceType("video").generate("snow_horses.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.

Else branch transformations

You can specify an alternative transformation to apply if the initial condition evaluates as false (and hence the transformations associated with the condition are not applied). To do this, use the if_else parameter to specify the fallback transformation.

For example, the following conditional transformation checks whether a video's aspect ratio is close to the desired aspect ratio, if it is close, then when the video is resized, any necessary padding is black. But if the aspect ratio is much smaller (for example, if it is a square or portrait video), then a blurred video padding is added.

Ruby:
Copy to clipboard
cl_video_tag("docs/parrot", :transformation=>[
  {:if=>"ar_gt_1.2"},
  {:background=>"black", :height=>320, :width=>480, :crop=>"pad"},
  {:if=>"else"},
  {:background=>"blurred:400:15", :height=>320, :width=>480, :crop=>"pad"},
  {:if=>"end"}
  ])
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('docs/parrot.mp4'))
  ->conditional(Conditional::ifCondition("aspect_ratio > 1.2",(new Transformation())
  ->resize(Resize::pad()->width(480)
->height(320)
  ->background(
  Background::color(Color::BLACK))
  ))
  ->otherwise((new Transformation())
  ->resize(Resize::pad()->width(480)
->height(320)
  ->background(
  Background::blurred()->intensity(400)
->brightness(15))
  ))
  );
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("docs/parrot", array("transformation"=>array(
  array("if"=>"ar_gt_1.2"),
  array("background"=>"black", "height"=>320, "width"=>480, "crop"=>"pad"),
  array("if"=>"else"),
  array("background"=>"blurred:400:15", "height"=>320, "width"=>480, "crop"=>"pad"),
  array("if"=>"end")
  )))
Python:
Copy to clipboard
CloudinaryVideo("docs/parrot").video(transformation=[
  {'if': "ar_gt_1.2"},
  {'background': "black", 'height': 320, 'width': 480, 'crop': "pad"},
  {'if': "else"},
  {'background': "blurred:400:15", 'height': 320, 'width': 480, 'crop': "pad"},
  {'if': "end"}
  ])
Node.js:
Copy to clipboard
cloudinary.video("docs/parrot", {transformation: [
  {if: "ar_gt_1.2"},
  {background: "black", height: 320, width: 480, crop: "pad"},
  {if: "else"},
  {background: "blurred:400:15", height: 320, width: 480, crop: "pad"},
  {if: "end"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .if("ar_gt_1.2").chain()
  .background("black").height(320).width(480).crop("pad").chain()
  .if("else").chain()
  .background("blurred:400:15").height(320).width(480).crop("pad").chain()
  .if("end")).videoTag("docs/parrot");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryVideo("docs/parrot.mp4").conditional(
  ifCondition(
    "aspect_ratio > 1.2",
    new MediaTransformation().resize(
      pad().width(480).height(320).background(color("black"))
    )
  ).otherwise(
    new MediaTransformation().resize(
      pad()
        .width(480)
        .height(320)
        .background(blurred().intensity(400).brightness(15))
    )
  )
);
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('docs/parrot', {transformation: [
  {if: "ar_gt_1.2"},
  {background: "black", height: 320, width: 480, crop: "pad"},
  {if: "else"},
  {background: "blurred:400:15", height: 320, width: 480, crop: "pad"},
  {if: "end"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("docs/parrot", {transformation: [
  {if: "ar_gt_1.2"},
  {background: "black", height: 320, width: 480, crop: "pad"},
  {if: "else"},
  {background: "blurred:400:15", height: 320, width: 480, crop: "pad"},
  {if: "end"}
  ]})
React:
Copy to clipboard
<Video publicId="docs/parrot" >
  <Transformation if="ar_gt_1.2" />
  <Transformation background="black" height="320" width="480" crop="pad" />
  <Transformation if="else" />
  <Transformation background="blurred:400:15" height="320" width="480" crop="pad" />
  <Transformation if="end" />
</Video>
Vue.js:
Copy to clipboard
<cld-video public-id="docs/parrot" >
  <cld-transformation if="ar_gt_1.2" />
  <cld-transformation background="black" height="320" width="480" crop="pad" />
  <cld-transformation if="else" />
  <cld-transformation background="blurred:400:15" height="320" width="480" crop="pad" />
  <cld-transformation if="end" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="docs/parrot" >
  <cl-transformation if="ar_gt_1.2">
  </cl-transformation>
  <cl-transformation background="black" height="320" width="480" crop="pad">
  </cl-transformation>
  <cl-transformation if="else">
  </cl-transformation>
  <cl-transformation background="blurred:400:15" height="320" width="480" crop="pad">
  </cl-transformation>
  <cl-transformation if="end">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .If("ar_gt_1.2").Chain()
  .Background("black").Height(320).Width(480).Crop("pad").Chain()
  .If("else").Chain()
  .Background("blurred:400:15").Height(320).Width(480).Crop("pad").Chain()
  .If("end")).BuildVideoTag("docs/parrot")
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setIf("ar_gt_1.2").chain()
  .setBackground("black").setHeight(320).setWidth(480).setCrop("pad").chain()
  .setIf("else").chain()
  .setBackground("blurred:400:15").setHeight(320).setWidth(480).setCrop("pad").chain()
  .setIf("end")).generate("docs/parrot.mp4")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .if("ar_gt_1.2").chain()
  .background("black").height(320).width(480).crop("pad").chain()
  .if("else").chain()
  .background("blurred:400:15").height(320).width(480).crop("pad").chain()
  .if("end")).resourceType("video").generate("docs/parrot.mp4");
Kotlin:
Copy to clipboard
// This code example is not currently available.

✔️ Feedback sent!

Rate this page: