Relative size overlays

Resize overlays to a given percentage of the main image, either related to width, height or both by setting the flags parameter to relative (fl_relative in URLs) while also setting the width and/or height parameters to the percentage value you need, represented by a decimal value (e.g., 0.4 for 40%).

Let's say we want to overlay the following black bar:

Ruby:
cl_image_tag("black_bar.png")
PHP:
cl_image_tag("black_bar.png")
Python:
CloudinaryImage("black_bar.png").image()
Node.js:
cloudinary.image("black_bar.png")
Java:
cloudinary.url().imageTag("black_bar.png")
JS:
cl.imageTag('black_bar.png').toHtml();
jQuery:
$.cloudinary.image("black_bar.png")
React:
<Image publicId="black_bar.png" >

</Image>
Angular:
<cl-image public-id="black_bar.png" >

</cl-image>
.Net:
cloudinary.Api.UrlImgUp.BuildImageTag("black_bar.png")
Android:
MediaManager.get().url().generate("black_bar.png")
Overlay image
on top of the following image:
Ruby:
cl_image_tag("lupine.jpg")
PHP:
cl_image_tag("lupine.jpg")
Python:
CloudinaryImage("lupine.jpg").image()
Node.js:
cloudinary.image("lupine.jpg")
Java:
cloudinary.url().imageTag("lupine.jpg")
JS:
cl.imageTag('lupine.jpg').toHtml();
jQuery:
$.cloudinary.image("lupine.jpg")
React:
<Image publicId="lupine.jpg" >

</Image>
Angular:
<cl-image public-id="lupine.jpg" >

</cl-image>
.Net:
cloudinary.Api.UrlImgUp.BuildImageTag("lupine.jpg")
Android:
MediaManager.get().url().generate("lupine.jpg")
Main image

The overlay image can be resized by specifying its dimensions with an absolute value in pixels. For example, 500px width and 200px height:

Ruby:
cl_image_tag("lupine.jpg", :overlay=>"black_bar", :height=>200, :width=>500)
PHP:
cl_image_tag("lupine.jpg", array("overlay"=>"black_bar", "height"=>200, "width"=>500))
Python:
CloudinaryImage("lupine.jpg").image(overlay="black_bar", height=200, width=500)
Node.js:
cloudinary.image("lupine.jpg", {overlay: "black_bar", height: 200, width: 500})
Java:
cloudinary.url().transformation(new Transformation().overlay("black_bar").height(200).width(500)).imageTag("lupine.jpg")
JS:
cl.imageTag('lupine.jpg', {overlay: "black_bar", height: 200, width: 500}).toHtml();
jQuery:
$.cloudinary.image("lupine.jpg", {overlay: "black_bar", height: 200, width: 500})
React:
<Image publicId="lupine.jpg" >
  <Transformation overlay="black_bar" height="200" width="500" />
</Image>
Angular:
<cl-image public-id="lupine.jpg" >
  <cl-transformation overlay="black_bar" height="200" width="500">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Overlay("black_bar").Height(200).Width(500)).BuildImageTag("lupine.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().overlay("black_bar").height(200).width(500)).generate("lupine.jpg")
Absolute value

However, there are cases where you might not know the exact dimensions of the main image, therefore using fixed dimensions won't always deliver the exact result you expect. You can tell Cloudinary to overlay the image while resizing it to a relative percentage of the containing image by using the relative flag alongside the dimensions you wish. For example, here's how to place the overlay black bar to fit 100% of the main image's width and 10% of the image's height:

Ruby:
cl_image_tag("lupine.jpg", :overlay=>"black_bar", :width=>1.0, :height=>0.1, :flags=>"relative")
PHP:
cl_image_tag("lupine.jpg", array("overlay"=>"black_bar", "width"=>1.0, "height"=>0.1, "flags"=>"relative"))
Python:
CloudinaryImage("lupine.jpg").image(overlay="black_bar", width=1.0, height=0.1, flags="relative")
Node.js:
cloudinary.image("lupine.jpg", {overlay: "black_bar", width: "1.0", height: "0.1", flags: "relative"})
Java:
cloudinary.url().transformation(new Transformation().overlay("black_bar").width(1.0).height(0.1).flags("relative")).imageTag("lupine.jpg")
JS:
cl.imageTag('lupine.jpg', {overlay: "black_bar", width: "1.0", height: "0.1", flags: "relative"}).toHtml();
jQuery:
$.cloudinary.image("lupine.jpg", {overlay: "black_bar", width: "1.0", height: "0.1", flags: "relative"})
React:
<Image publicId="lupine.jpg" >
  <Transformation overlay="black_bar" width="1.0" height="0.1" flags="relative" />
</Image>
Angular:
<cl-image public-id="lupine.jpg" >
  <cl-transformation overlay="black_bar" width="1.0" height="0.1" flags="relative">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Overlay("black_bar").Width(1.0).Height(0.1).Flags("relative")).BuildImageTag("lupine.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().overlay("black_bar").width(1.0).height(0.1).flags("relative")).generate("lupine.jpg")
100% width-related

This feature can also be applied to an image that is used as a background for text. The following example demonstrates the same dimensioned black bar, while lowering its opacity to 60% and adding text on top of it:

Ruby:
cl_image_tag("lupine.jpg", :transformation=>[
  {:overlay=>"black_bar", :width=>1.0, :height=>0.1, :flags=>"relative", :opacity=>60},
  {:overlay=>"text:Arial_150_bold:Cloudinary", :color=>"white"}
  ])
PHP:
cl_image_tag("lupine.jpg", array("transformation"=>array(
  array("overlay"=>"black_bar", "width"=>1.0, "height"=>0.1, "flags"=>"relative", "opacity"=>60),
  array("overlay"=>"text:Arial_150_bold:Cloudinary", "color"=>"white")
  )))
Python:
CloudinaryImage("lupine.jpg").image(transformation=[
  {"overlay": "black_bar", "width": 1.0, "height": 0.1, "flags": "relative", "opacity": 60},
  {"overlay": "text:Arial_150_bold:Cloudinary", "color": "white"}
  ])
Node.js:
cloudinary.image("lupine.jpg", {transformation: [
  {overlay: "black_bar", width: "1.0", height: "0.1", flags: "relative", opacity: 60},
  {overlay: "text:Arial_150_bold:Cloudinary", color: "white"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .overlay("black_bar").width(1.0).height(0.1).flags("relative").opacity(60).chain()
  .overlay("text:Arial_150_bold:Cloudinary").color("white")).imageTag("lupine.jpg")
JS:
cl.imageTag('lupine.jpg', {transformation: [
  {overlay: "black_bar", width: "1.0", height: "0.1", flags: "relative", opacity: 60},
  {overlay: "text:Arial_150_bold:Cloudinary", color: "white"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("lupine.jpg", {transformation: [
  {overlay: "black_bar", width: "1.0", height: "0.1", flags: "relative", opacity: 60},
  {overlay: "text:Arial_150_bold:Cloudinary", color: "white"}
  ]})
React:
<Image publicId="lupine.jpg" >
  <Transformation overlay="black_bar" width="1.0" height="0.1" flags="relative" opacity="60" />
  <Transformation overlay="text:Arial_150_bold:Cloudinary" color="white" />
</Image>
Angular:
<cl-image public-id="lupine.jpg" >
  <cl-transformation overlay="black_bar" width="1.0" height="0.1" flags="relative" opacity="60">
  </cl-transformation>
  <cl-transformation overlay="text:Arial_150_bold:Cloudinary" color="white">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Overlay("black_bar").Width(1.0).Height(0.1).Flags("relative").Opacity(60).Chain()
  .Overlay("text:Arial_150_bold:Cloudinary").Color("white")).BuildImageTag("lupine.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .overlay("black_bar").width(1.0).height(0.1).flags("relative").opacity(60).chain()
  .overlay("text:Arial_150_bold:Cloudinary").color("white")).generate("lupine.jpg")
Including text

by Itay Taragano