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 overlay="text:arial_60:Sea%20Shell" gravity="north" y=20 />
</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")
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 overlay="text:courier_60_bold_italic_underline:Sea%20Shell" gravity="north" y=20 />
</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")
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 overlay="text:helvetica_80_bold:Sea%20Shell" gravity="north" y=20 color="blue" />
</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")
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 overlay="text:helvetica_80_bold:Sea%20Shell" gravity="north" y=20 color="#8b0f02" opacity=50 />
</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")
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 overlay="black_bar" gravity="south" width=1.0 height=0.12 flags="relative" opacity=60 />
        <cl-transformation overlay="text:Doppio%20One_20:Photographer:%20Jonathan%20Doe" gravity="south_west" y=5 x=10 color="#eee" />
</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")
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 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-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")
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 overlay="text:Courgette_22:Dear%20customer" angle=9 opacity=80 gravity="north_west" y=25 x=64 color="#671537" />
        <cl-transformation overlay="text:Niconne_20:Sincerely%20yours" gravity="south" x=-10 y=120 color="#15376f" angle=9 />
        <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-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")
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

Serverless Tutorial: File Storage with Webtask and Cloudinary

Media makes up the majority of today's website content. While it makes websites more interesting for visitors, media presents challenges because these images and videos are more difficult to store, deliver and manipulate on-the-fly to suit any given situation.

Read more

ImageCon17: Delivering Responsive Images

By Jason Grigsby

After five years many specifications, some inflamed Twitter battles and other conversations, responsive images have finally landed and there's a sound. Which is really exciting right? People have been climbing for this for quite some time and we've reached a point where they're available in modern browsers. So people were excited, they wanted to go use them it's something that designers and developers have had as a point of frustration for a long time.

Read more
Auto padding images with content-aware color padding

How you present the content of your website can be just as important as the content itself. The images you display need to conform to the graphic design of your site, and every image needs to fit within a predefined size. Although that may be simple enough to achieve when you are dealing with your own images, the task can be more challenging when displaying images uploaded by your users.

Read more

Bounce! Hacking Jazzfest with Social Videos

By Eric Normand
Bounce! Hacking Jazzfest with Social Videos

Last week, I was invited to an exclusive hackathon to build apps for musicians. The app team I was assigned to was tasked with building a video upload site for Bounce videos. Bounce is a style of music that originated in New Orleans. The app would be called BounceDotCom.com and there were plans to have Big Freedia, the Queen of Bounce, promote it. I knew the organizer could make things happen, so I jumped at the chance.

Read more
Getting a Better React-ion with Progressive Web Apps

This is part 2 of a 3 part series

React has become more popular, as well as more mature, over the last four years since its release by Facebook. It has become one of the go-to technologies for people looking to componentize the front-end of any web application. It also helps that an entire mobile stack is built around React in the form of ReactNative. The components are wonderful, however there can be a burdensome learning curve. But, in the end, there’s the payoff of highly reusable code and a better user experience.

Read more
Build an Image Library with React & Cloudinary

This article was originally posted on Scotch.io

React is a good tool when it comes to building flexible and reusable UI components. However, it's "one of those libraries" that cannot handle all the tasks involved in building a full fleshed UI project. Other supporting tools - such as a recently announced React SDK from Cloudinary - are available to provide solutions that the React core cannot.

Read more