Cloudinary Blog

How to overlay text on image easily, pixel perfect and with no CSS/HTML

Overlay text on image, pixel perfect with no CSS/HTML

Our customers frequently ask us if we can help them apply dynamic text overlays over images. While a common approach is to add text elements in your pages using HTML elements, CSS or native mobile UI controls, in many cases it's preferable to create images with text layers already included. It makes it simpler to display rich content on different media channels and devices, while ensuring a pixel-perfect result as your graphic designer envisioned.

Text overlays on images can be used to embed a caption, a photographer's name or a watermark for copyright reasons. It can also be used to embed dynamic images in emails that have limited visual customization capabilities, dynamic building of advertisement banners with variable content, dynamic creation of print materials (e.g., coupons, greeting cards, business cards) and more.

Cloudinary's cloud-based image management service allows you to upload images, specify a given text, and dynamically overlay it over your images and photos. Cloudinary does the image processing on the fly, and returns a new image which includes the required text layer. We've already shown in previous posts how you can create text layers using authenticated API calls and use text layers to build dynamic banners.

You can now use Cloudinary's image manipulation URLs to add text layers to images on-the-fly, while selecting any font out of a set of hundreds of fonts. You can also further customize and manipulate your text layers to achieve the desired look and feel. All this is done in the cloud using dynamic URLs (no authenticated API calls are required).

Dynamic styles

Cloudinary's dynamic manipulation URL allows you to add a text overlay while specifying the font, the actual text content, and customizing the look and feel.

For example, the following dynamic URL added the label 'Sea Shell' as an overlay on a previously-uploaded image named sea_shell.jpg. The component that starts with l_text: is followed by the font name and size and then the actual 'Sea Shell' label. The overlay is positioned 20 pixels from the top of the containing image by setting the gravity parameter to north (or g_north in the URL). In this example, we added a label using the Arial font of size 60 pixels.

Ruby:
cl_image_tag("sea_shell.jpg", :transformation=>[
  {:width=>400, :crop=>"scale"},
  {:overlay=>"text:arial_60:Sea%20Shell", :gravity=>"north", :y=>20}
  ])
PHP:
cl_image_tag("sea_shell.jpg", array("transformation"=>array(
  array("width"=>400, "crop"=>"scale"),
  array("overlay"=>"text:arial_60:Sea%20Shell", "gravity"=>"north", "y"=>20)
  )))
Python:
CloudinaryImage("sea_shell.jpg").image(transformation=[
  {"width": 400, "crop": "scale"},
  {"overlay": "text:arial_60:Sea%20Shell", "gravity": "north", "y": 20}
  ])
Node.js:
cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:arial_60:Sea%20Shell", gravity: "north", y: 20}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:arial_60:Sea%20Shell").gravity("north").y(20)).imageTag("sea_shell.jpg")
JS:
cl.imageTag('sea_shell.jpg', {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:arial_60:Sea%20Shell", gravity: "north", y: 20}
  ]}).toHtml();
jQuery:
$.cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:arial_60:Sea%20Shell", gravity: "north", y: 20}
  ]})
React:
<Image publicId="sea_shell.jpg" >
  <Transformation width="400" crop="scale" />
  <Transformation overlay="text:arial_60:Sea%20Shell" gravity="north" y="20" />
</Image>
Angular:
<cl-image public-id="sea_shell.jpg" >
  <cl-transformation width="400" crop="scale">
  </cl-transformation>
  <cl-transformation overlay="text:arial_60:Sea%20Shell" gravity="north" y="20">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(400).Crop("scale").Chain()
  .Overlay("text:arial_60:Sea%20Shell").Gravity("north").Y(20)).BuildImageTag("sea_shell.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:arial_60:Sea%20Shell").gravity("north").y(20)).generate("sea_shell.jpg")
Sea shell photo with text overlay

You can click on the tabs in the example above to see how to build this dynamic manipulation URL using Cloudinary's client libraries for Ruby on Rails, Python & Django, PHP, Node.js, Java and .Net.

Cloudinary supports hundreds of fonts, include all Google’s Web Fonts. You can specify the name of the font in manipulation URLs (case insensitive). In addition, you can specify any standard font customization by appending one or more of the following directives: bold, italic, underline, strikethrough, center, left, right.

The following example URL and client libraries code adds the same label, this time using the Courier font with bold, italic and underline:

Ruby:
cl_image_tag("sea_shell.jpg", :transformation=>[
  {:width=>400, :crop=>"scale"},
  {:overlay=>"text:courier_60_bold_italic_underline:Sea%20Shell", :gravity=>"north", :y=>20}
  ])
PHP:
cl_image_tag("sea_shell.jpg", array("transformation"=>array(
  array("width"=>400, "crop"=>"scale"),
  array("overlay"=>"text:courier_60_bold_italic_underline:Sea%20Shell", "gravity"=>"north", "y"=>20)
  )))
Python:
CloudinaryImage("sea_shell.jpg").image(transformation=[
  {"width": 400, "crop": "scale"},
  {"overlay": "text:courier_60_bold_italic_underline:Sea%20Shell", "gravity": "north", "y": 20}
  ])
Node.js:
cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:courier_60_bold_italic_underline:Sea%20Shell", gravity: "north", y: 20}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:courier_60_bold_italic_underline:Sea%20Shell").gravity("north").y(20)).imageTag("sea_shell.jpg")
JS:
cl.imageTag('sea_shell.jpg', {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:courier_60_bold_italic_underline:Sea%20Shell", gravity: "north", y: 20}
  ]}).toHtml();
jQuery:
$.cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:courier_60_bold_italic_underline:Sea%20Shell", gravity: "north", y: 20}
  ]})
React:
<Image publicId="sea_shell.jpg" >
  <Transformation width="400" crop="scale" />
  <Transformation overlay="text:courier_60_bold_italic_underline:Sea%20Shell" gravity="north" y="20" />
</Image>
Angular:
<cl-image public-id="sea_shell.jpg" >
  <cl-transformation width="400" crop="scale">
  </cl-transformation>
  <cl-transformation overlay="text:courier_60_bold_italic_underline:Sea%20Shell" gravity="north" y="20">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(400).Crop("scale").Chain()
  .Overlay("text:courier_60_bold_italic_underline:Sea%20Shell").Gravity("north").Y(20)).BuildImageTag("sea_shell.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:courier_60_bold_italic_underline:Sea%20Shell").gravity("north").y(20)).generate("sea_shell.jpg")
Sea shell photo with Courier bold, italic and underline text overlay

Colors and opacity

The color of the text overlay can be selected to match your graphic design by setting the color manipulation parameter (or co for URLs) to a color name or an RGB representation. The example below added the ‘Sea Shell’ label colored blue and this time using the bold Helvetica font of size 80 pixels.

Ruby:
cl_image_tag("sea_shell.jpg", :transformation=>[
  {:width=>400, :crop=>"scale"},
  {:overlay=>"text:helvetica_80_bold:Sea%20Shell", :gravity=>"north", :y=>20, :color=>"blue"}
  ])
PHP:
cl_image_tag("sea_shell.jpg", array("transformation"=>array(
  array("width"=>400, "crop"=>"scale"),
  array("overlay"=>"text:helvetica_80_bold:Sea%20Shell", "gravity"=>"north", "y"=>20, "color"=>"blue")
  )))
Python:
CloudinaryImage("sea_shell.jpg").image(transformation=[
  {"width": 400, "crop": "scale"},
  {"overlay": "text:helvetica_80_bold:Sea%20Shell", "gravity": "north", "y": 20, "color": "blue"}
  ])
Node.js:
cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:helvetica_80_bold:Sea%20Shell", gravity: "north", y: 20, color: "blue"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:helvetica_80_bold:Sea%20Shell").gravity("north").y(20).color("blue")).imageTag("sea_shell.jpg")
JS:
cl.imageTag('sea_shell.jpg', {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:helvetica_80_bold:Sea%20Shell", gravity: "north", y: 20, color: "blue"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:helvetica_80_bold:Sea%20Shell", gravity: "north", y: 20, color: "blue"}
  ]})
React:
<Image publicId="sea_shell.jpg" >
  <Transformation width="400" crop="scale" />
  <Transformation overlay="text:helvetica_80_bold:Sea%20Shell" gravity="north" y="20" color="blue" />
</Image>
Angular:
<cl-image public-id="sea_shell.jpg" >
  <cl-transformation width="400" crop="scale">
  </cl-transformation>
  <cl-transformation overlay="text:helvetica_80_bold:Sea%20Shell" gravity="north" y="20" color="blue">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(400).Crop("scale").Chain()
  .Overlay("text:helvetica_80_bold:Sea%20Shell").Gravity("north").Y(20).Color("blue")).BuildImageTag("sea_shell.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:helvetica_80_bold:Sea%20Shell").gravity("north").y(20).color("blue")).generate("sea_shell.jpg")
Blue colored Helvetica text overlay

The opacity parameter (or o for URLs) can be set to a value between 0 and 100 to make the text overlay semi-transparent. As you can see in the example below, a semi-transparent red label was added as an overlay:

Ruby:
cl_image_tag("sea_shell.jpg", :transformation=>[
  {:width=>400, :crop=>"scale"},
  {:overlay=>"text:helvetica_80_bold:Sea%20Shell", :gravity=>"north", :y=>20, :color=>"#8b0f02", :opacity=>50}
  ])
PHP:
cl_image_tag("sea_shell.jpg", array("transformation"=>array(
  array("width"=>400, "crop"=>"scale"),
  array("overlay"=>"text:helvetica_80_bold:Sea%20Shell", "gravity"=>"north", "y"=>20, "color"=>"#8b0f02", "opacity"=>50)
  )))
Python:
CloudinaryImage("sea_shell.jpg").image(transformation=[
  {"width": 400, "crop": "scale"},
  {"overlay": "text:helvetica_80_bold:Sea%20Shell", "gravity": "north", "y": 20, "color": "#8b0f02", "opacity": 50}
  ])
Node.js:
cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:helvetica_80_bold:Sea%20Shell", gravity: "north", y: 20, color: "#8b0f02", opacity: 50}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:helvetica_80_bold:Sea%20Shell").gravity("north").y(20).color("#8b0f02").opacity(50)).imageTag("sea_shell.jpg")
JS:
cl.imageTag('sea_shell.jpg', {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:helvetica_80_bold:Sea%20Shell", gravity: "north", y: 20, color: "#8b0f02", opacity: 50}
  ]}).toHtml();
jQuery:
$.cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "text:helvetica_80_bold:Sea%20Shell", gravity: "north", y: 20, color: "#8b0f02", opacity: 50}
  ]})
React:
<Image publicId="sea_shell.jpg" >
  <Transformation width="400" crop="scale" />
  <Transformation overlay="text:helvetica_80_bold:Sea%20Shell" gravity="north" y="20" color="#8b0f02" opacity="50" />
</Image>
Angular:
<cl-image public-id="sea_shell.jpg" >
  <cl-transformation width="400" crop="scale">
  </cl-transformation>
  <cl-transformation overlay="text:helvetica_80_bold:Sea%20Shell" gravity="north" y="20" color="#8b0f02" opacity="50">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(400).Crop("scale").Chain()
  .Overlay("text:helvetica_80_bold:Sea%20Shell").Gravity("north").Y(20).Color("#8b0f02").Opacity(50)).BuildImageTag("sea_shell.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("text:helvetica_80_bold:Sea%20Shell").gravity("north").y(20).color("#8b0f02").opacity(50)).generate("sea_shell.jpg")
Semi transparent text overlay

One of the common examples of text overlay is to add a caption with photo description and credits. The example above added an overlay with a credit to the photographer. This time we used the Doppio font while adding a semi transparent black overlay at the bottom of the photo, underlying the white text.

Ruby:
cl_image_tag("sea_shell.jpg", :transformation=>[
  {:width=>400, :crop=>"scale"},
  {:overlay=>"black_bar", :gravity=>"south", :width=>1.0, :height=>0.12, :flags=>"relative", :opacity=>60},
  {:overlay=>"text:Doppio%20One_20:Photographer:%20Jonathan%20Doe", :gravity=>"south_west", :y=>5, :x=>10, :color=>"#eee"}
  ])
PHP:
cl_image_tag("sea_shell.jpg", array("transformation"=>array(
  array("width"=>400, "crop"=>"scale"),
  array("overlay"=>"black_bar", "gravity"=>"south", "width"=>1.0, "height"=>0.12, "flags"=>"relative", "opacity"=>60),
  array("overlay"=>"text:Doppio%20One_20:Photographer:%20Jonathan%20Doe", "gravity"=>"south_west", "y"=>5, "x"=>10, "color"=>"#eee")
  )))
Python:
CloudinaryImage("sea_shell.jpg").image(transformation=[
  {"width": 400, "crop": "scale"},
  {"overlay": "black_bar", "gravity": "south", "width": 1.0, "height": 0.12, "flags": "relative", "opacity": 60},
  {"overlay": "text:Doppio%20One_20:Photographer:%20Jonathan%20Doe", "gravity": "south_west", "y": 5, "x": 10, "color": "#eee"}
  ])
Node.js:
cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "black_bar", gravity: "south", width: "1.0", height: "0.12", flags: "relative", opacity: 60},
  {overlay: "text:Doppio%20One_20:Photographer:%20Jonathan%20Doe", gravity: "south_west", y: 5, x: 10, color: "#eee"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("black_bar").gravity("south").width(1.0).height(0.12).flags("relative").opacity(60).chain()
  .overlay("text:Doppio%20One_20:Photographer:%20Jonathan%20Doe").gravity("south_west").y(5).x(10).color("#eee")).imageTag("sea_shell.jpg")
JS:
cl.imageTag('sea_shell.jpg', {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "black_bar", gravity: "south", width: "1.0", height: "0.12", flags: "relative", opacity: 60},
  {overlay: "text:Doppio%20One_20:Photographer:%20Jonathan%20Doe", gravity: "south_west", y: 5, x: 10, color: "#eee"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("sea_shell.jpg", {transformation: [
  {width: 400, crop: "scale"},
  {overlay: "black_bar", gravity: "south", width: "1.0", height: "0.12", flags: "relative", opacity: 60},
  {overlay: "text:Doppio%20One_20:Photographer:%20Jonathan%20Doe", gravity: "south_west", y: 5, x: 10, color: "#eee"}
  ]})
React:
<Image publicId="sea_shell.jpg" >
  <Transformation width="400" crop="scale" />
  <Transformation overlay="black_bar" gravity="south" width="1.0" height="0.12" flags="relative" opacity="60" />
  <Transformation overlay="text:Doppio%20One_20:Photographer:%20Jonathan%20Doe" gravity="south_west" y="5" x="10" color="#eee" />
</Image>
Angular:
<cl-image public-id="sea_shell.jpg" >
  <cl-transformation width="400" crop="scale">
  </cl-transformation>
  <cl-transformation overlay="black_bar" gravity="south" width="1.0" height="0.12" flags="relative" opacity="60">
  </cl-transformation>
  <cl-transformation overlay="text:Doppio%20One_20:Photographer:%20Jonathan%20Doe" gravity="south_west" y="5" x="10" color="#eee">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(400).Crop("scale").Chain()
  .Overlay("black_bar").Gravity("south").Width(1.0).Height(0.12).Flags("relative").Opacity(60).Chain()
  .Overlay("text:Doppio%20One_20:Photographer:%20Jonathan%20Doe").Gravity("south_west").Y(5).X(10).Color("#eee")).BuildImageTag("sea_shell.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(400).crop("scale").chain()
  .overlay("black_bar").gravity("south").width(1.0).height(0.12).flags("relative").opacity(60).chain()
  .overlay("text:Doppio%20One_20:Photographer:%20Jonathan%20Doe").gravity("south_west").y(5).x(10).color("#eee")).generate("sea_shell.jpg")
Credits caption semi-transparent text overlay

Multi-line text justification and wrapping

You may want to embed a longer text in your generated images. If so, you’ll need the text to be automatically wrapped into lines. You’ll also want to control the alignment of your text.

As you can see in the example below, a long text was overlaid over a previously uploaded image named ‘envelope.jpg’. The dynamic text layer is automatically wrapped and also aligned to the center. We specified the fit crop mode and defined a maximum width of 200 pixels, which tells Cloudinary to automatically wrap the actual text content. In addition, we rotated the generated text layer 9 degrees, to better fit in the background image (using the angle parameter, or a in the manipulation URL sample). This time we used the Neucha font, size 16 pixels, with center alignment.

Ruby:
cl_image_tag("envelope.jpg", :transformation=>[
  {:width=>300, :crop=>"scale"},
  {:gravity=>"north", :x=>0, :y=>54, :width=>200, :angle=>9, :overlay=>"text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", :crop=>"fit"}
  ])
PHP:
cl_image_tag("envelope.jpg", array("transformation"=>array(
  array("width"=>300, "crop"=>"scale"),
  array("gravity"=>"north", "x"=>0, "y"=>54, "width"=>200, "angle"=>9, "overlay"=>"text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", "crop"=>"fit")
  )))
Python:
CloudinaryImage("envelope.jpg").image(transformation=[
  {"width": 300, "crop": "scale"},
  {"gravity": "north", "x": 0, "y": 54, "width": 200, "angle": 9, "overlay": "text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", "crop": "fit"}
  ])
Node.js:
cloudinary.image("envelope.jpg", {transformation: [
  {width: 300, crop: "scale"},
  {gravity: "north", x: 0, y: 54, width: 200, angle: 9, overlay: "text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", crop: "fit"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(300).crop("scale").chain()
  .gravity("north").x(0).y(54).width(200).angle(9).overlay("text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.").crop("fit")).imageTag("envelope.jpg")
JS:
cl.imageTag('envelope.jpg', {transformation: [
  {width: 300, crop: "scale"},
  {gravity: "north", x: 0, y: 54, width: 200, angle: 9, overlay: "text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", crop: "fit"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("envelope.jpg", {transformation: [
  {width: 300, crop: "scale"},
  {gravity: "north", x: 0, y: 54, width: 200, angle: 9, overlay: "text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", crop: "fit"}
  ]})
React:
<Image publicId="envelope.jpg" >
  <Transformation width="300" crop="scale" />
  <Transformation gravity="north" x="0" y="54" width="200" angle="9" overlay="text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat." crop="fit" />
</Image>
Angular:
<cl-image public-id="envelope.jpg" >
  <cl-transformation width="300" crop="scale">
  </cl-transformation>
  <cl-transformation gravity="north" x="0" y="54" width="200" angle="9" overlay="text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat." crop="fit">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(300).Crop("scale").Chain()
  .Gravity("north").X(0).Y(54).Width(200).Angle(9).Overlay("text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.").Crop("fit")).BuildImageTag("envelope.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(300).crop("scale").chain()
  .gravity("north").x(0).y(54).width(200).angle(9).overlay("text:Neucha_16_center:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.").crop("fit")).generate("envelope.jpg")
Rotated multi-line text overlay

Building print material with multiple text layers

All examples above added a single text overlay. You can use Cloudinary’s manipulation URLs to chain multiple overlays, generating a resulting image that is delivered optimized via a CDN to your users.

Cloudinary’s client libraries can be used to build chained transformation URLs with multiple text overlays. You can also directly build these URLs by separating the different components with /.

The following example used the same background envelope.jpg image. This time adding 3 different text overlays. Each text overlay uses a different set of font family, font size, color and positioning. The result is quite cool and professional, isn’t it?

Ruby:
cl_image_tag("envelope.jpg", :transformation=>[
  {:width=>300, :crop=>"scale"},
  {:overlay=>"text:Courgette_22:Dear%20customer", :angle=>9, :opacity=>80, :gravity=>"north_west", :y=>25, :x=>64, :color=>"#671537"},
  {:overlay=>"text:Niconne_20:Sincerely%20yours", :gravity=>"south", :x=>-10, :y=>120, :color=>"#15376f", :angle=>9},
  {:gravity=>"north", :x=>0, :y=>54, :width=>200, :angle=>9, :overlay=>"text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", :crop=>"fit"}
  ])
PHP:
cl_image_tag("envelope.jpg", array("transformation"=>array(
  array("width"=>300, "crop"=>"scale"),
  array("overlay"=>"text:Courgette_22:Dear%20customer", "angle"=>9, "opacity"=>80, "gravity"=>"north_west", "y"=>25, "x"=>64, "color"=>"#671537"),
  array("overlay"=>"text:Niconne_20:Sincerely%20yours", "gravity"=>"south", "x"=>-10, "y"=>120, "color"=>"#15376f", "angle"=>9),
  array("gravity"=>"north", "x"=>0, "y"=>54, "width"=>200, "angle"=>9, "overlay"=>"text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", "crop"=>"fit")
  )))
Python:
CloudinaryImage("envelope.jpg").image(transformation=[
  {"width": 300, "crop": "scale"},
  {"overlay": "text:Courgette_22:Dear%20customer", "angle": 9, "opacity": 80, "gravity": "north_west", "y": 25, "x": 64, "color": "#671537"},
  {"overlay": "text:Niconne_20:Sincerely%20yours", "gravity": "south", "x": -10, "y": 120, "color": "#15376f", "angle": 9},
  {"gravity": "north", "x": 0, "y": 54, "width": 200, "angle": 9, "overlay": "text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", "crop": "fit"}
  ])
Node.js:
cloudinary.image("envelope.jpg", {transformation: [
  {width: 300, crop: "scale"},
  {overlay: "text:Courgette_22:Dear%20customer", angle: 9, opacity: 80, gravity: "north_west", y: 25, x: 64, color: "#671537"},
  {overlay: "text:Niconne_20:Sincerely%20yours", gravity: "south", x: -10, y: 120, color: "#15376f", angle: 9},
  {gravity: "north", x: 0, y: 54, width: 200, angle: 9, overlay: "text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", crop: "fit"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(300).crop("scale").chain()
  .overlay("text:Courgette_22:Dear%20customer").angle(9).opacity(80).gravity("north_west").y(25).x(64).color("#671537").chain()
  .overlay("text:Niconne_20:Sincerely%20yours").gravity("south").x(-10).y(120).color("#15376f").angle(9).chain()
  .gravity("north").x(0).y(54).width(200).angle(9).overlay("text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.").crop("fit")).imageTag("envelope.jpg")
JS:
cl.imageTag('envelope.jpg', {transformation: [
  {width: 300, crop: "scale"},
  {overlay: "text:Courgette_22:Dear%20customer", angle: 9, opacity: 80, gravity: "north_west", y: 25, x: 64, color: "#671537"},
  {overlay: "text:Niconne_20:Sincerely%20yours", gravity: "south", x: -10, y: 120, color: "#15376f", angle: 9},
  {gravity: "north", x: 0, y: 54, width: 200, angle: 9, overlay: "text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", crop: "fit"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("envelope.jpg", {transformation: [
  {width: 300, crop: "scale"},
  {overlay: "text:Courgette_22:Dear%20customer", angle: 9, opacity: 80, gravity: "north_west", y: 25, x: 64, color: "#671537"},
  {overlay: "text:Niconne_20:Sincerely%20yours", gravity: "south", x: -10, y: 120, color: "#15376f", angle: 9},
  {gravity: "north", x: 0, y: 54, width: 200, angle: 9, overlay: "text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.", crop: "fit"}
  ]})
React:
<Image publicId="envelope.jpg" >
  <Transformation width="300" crop="scale" />
  <Transformation overlay="text:Courgette_22:Dear%20customer" angle="9" opacity="80" gravity="north_west" y="25" x="64" color="#671537" />
  <Transformation overlay="text:Niconne_20:Sincerely%20yours" gravity="south" x="-10" y="120" color="#15376f" angle="9" />
  <Transformation gravity="north" x="0" y="54" width="200" angle="9" overlay="text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat." crop="fit" />
</Image>
Angular:
<cl-image public-id="envelope.jpg" >
  <cl-transformation width="300" crop="scale">
  </cl-transformation>
  <cl-transformation overlay="text:Courgette_22:Dear%20customer" angle="9" opacity="80" gravity="north_west" y="25" x="64" color="#671537">
  </cl-transformation>
  <cl-transformation overlay="text:Niconne_20:Sincerely%20yours" gravity="south" x="-10" y="120" color="#15376f" angle="9">
  </cl-transformation>
  <cl-transformation gravity="north" x="0" y="54" width="200" angle="9" overlay="text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat." crop="fit">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(300).Crop("scale").Chain()
  .Overlay("text:Courgette_22:Dear%20customer").Angle(9).Opacity(80).Gravity("north_west").Y(25).X(64).Color("#671537").Chain()
  .Overlay("text:Niconne_20:Sincerely%20yours").Gravity("south").X(-10).Y(120).Color("#15376f").Angle(9).Chain()
  .Gravity("north").X(0).Y(54).Width(200).Angle(9).Overlay("text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.").Crop("fit")).BuildImageTag("envelope.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
  .width(300).crop("scale").chain()
  .overlay("text:Courgette_22:Dear%20customer").angle(9).opacity(80).gravity("north_west").y(25).x(64).color("#671537").chain()
  .overlay("text:Niconne_20:Sincerely%20yours").gravity("south").x(-10).y(120).color("#15376f").angle(9).chain()
  .gravity("north").x(0).y(54).width(200).angle(9).overlay("text:Neucha_16:Lorem%20ipsum%20dolor%20sit%20amet%20consectetur%20adipisicing%20elit%20sed%20do%20eiusmod%20tempor%20incididunt%20ut%20labore%20et%20dolore%20magna%20aliqua.%20Ut%20enim%20ad%20minim%20veniam%20quis%20nostrud%20exercitation%20ullamco%20laboris%20nisi%20ut%20aliquip%20ex%20ea%20commodo%20consequat.").crop("fit")).generate("envelope.jpg")
Multiple text overlays of multiple lines and styles

Summary

As we already know from many of our customers, adding text overlays to images and photos is useful for many use cases. The addition of dynamic text styles and content that you can use, as an on-the-fly manipulation of images uploaded to Cloudinary, makes the process much simpler and more dynamic. The resulting images can be embedded in your website, mobile application or marketing emails, while ensuring that your users see it exactly as designed without any browser or device-specific customization.

Text overlay URLs with dynamic styles, as well as client library support for generating these URLs using Ruby on Rails, Python & Django, PHP, Node.js, Java and .Net, is available of all Cloudinary plans, including the free plan. If you don’t have an account yet, get a free account and try it out for yourself. We’d also love to hear your feedback on this feature in the comments below, or via Facebook or Twitter.

Recent Blog Posts

Automatically moderate your user uploaded images

Allowing your users to upload their own images to your website can increase user engagement, retention and monetization. However, allowing your users to upload any image they want to, may lead to some of your users uploading inappropriate images to your application. These images may offend other users or even cause your site to violate standards or regulations.

Read more
Cloudinary Uses Scale API to Focus on Image Compression

Here at Cloudinary, we provide a cloud-based tool that enables our users to compress images and video for their websites and apps. Our goal is to preserve the visual integrity of the content, but deliver the smallest file size to any device or browser to ultimately optimize website performance and end user satisfaction.

Read more
CloudinaryAndroid SDK

Developing applications for mobile consumption requires facing, and overcoming, some difficult challenges. Apps need to limit their RAM, CPU and battery usage while still performing the required tasks in a reasonable time frame. If too many background tasks are running, the mobile device can become sluggish, with the battery running out very quickly. Coordination with other apps is crucial to keep the device responsive and make the battery last longer.

Read more
forLoop: Nigeria Event on Building for The Next Billion Users

TL;DR

Since Google shared their intent for the next billion internet users, some African developers thought this was pointing right at them and they needed to act fast. The mission to bring the next billion users from Africa to the internet kicked off a storm of enthusiasm. This community event turned into a success story and this is a summary of what happened.

Read more