Create images from text
Last updated: Jun-25-2024
You can use Cloudinary to dynamically generate an image from a given textual string using the text
method of the Upload API. For example, to create an image from the text string "Hello World":
cloudinary.v2.uploader
.text('Hello World')
.then(result=>console.log(result));
Optional parameters
You can also optionally include various font, color and style parameters that can be specified to customize the look & feel of the text based image. For a full listing of the possible optional parameters available for the text
method, see the Upload API reference.
For example, to create an image of the text string "Sample Name" in 12 point, black, Arial font with 90% opacity, and the public ID of "dark_name":
cloudinary.v2.uploader
.text("Sample Name",
{ public_id: "dark_name",
font_family: "Arial",
font_size: 12,
font_color: "black",
opacity: 90 })
.then(result=>console.log(result));
The resulting image will also include all the styling information stored as metadata, which means the resulting image can be referred to as a "text style" base for creating text overlays on the fly. See the documentation on Text style images for more information.
Response
The API call returns a JSON response including the URLs for accessing the generated image through a CDN, the assigned public ID and the current version of the resource.
For example:
{
"asset_id": "5f3a66a07429c5e36e8fb73bee30e860",
"public_id": "0cf83f1fab2760f36dcab598030f56ab",
"version": 1719311171,
"version_id": "4ecaa07afe4ea835874bf1e2268a9a05",
"signature": "e7ba4bcb56bdc6083eadeed2bf5bfd004c670c83",
"width": 73,
"height": 10,
"format": "png",
"resource_type": "image",
"created_at": "2024-06-25T10:26:11Z",
"tags": [],
"bytes": 746,
"type": "text",
"etag": "563af6387b3dd4c425e5dd38d0a8fe25",
"placeholder": false,
"url": "http://res.cloudinary.com/cld-docs/image/text/v1719311171/0cf83f1fab2760f36dcab598030f56ab.png",
"secure_url": "https://res.cloudinary.com/cld-docs/image/text/v1719311171/0cf83f1fab2760f36dcab598030f56ab.png",
"asset_folder": "",
"display_name": "0cf83f1fab2760f36dcab598030f56ab"
}