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")
jQuery:
$.cloudinary.image("black_bar.png")
.Net:
cloudinary.Api.UrlImgUp.BuildImageTag("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")
jQuery:
$.cloudinary.image("lupine.jpg")
.Net:
cloudinary.Api.UrlImgUp.BuildImageTag("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")
jQuery:
$.cloudinary.image("lupine.jpg", {overlay: "black_bar", height: 200, width: 500})
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Overlay("black_bar").Height(200).Width(500)).BuildImageTag("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")
jQuery:
$.cloudinary.image("lupine.jpg", {overlay: "black_bar", width: 1.0, height: 0.1, flags: "relative"})
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Overlay("black_bar").Width(1.0).Height(0.1).Flags("relative")).BuildImageTag("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")
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"}
  ]})
.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")
Including text

by Itay Taragano