Generate CDN-backed delivery URLs that resize, crop, overlay, or optimize an image. URL generation is local — no network call, no secret required — and the derived asset is created by Cloudinary on first request, then served from CDN cache.
For video, see Transform and deliver a video.
require "cloudinary" # only cloud_name is needed for URL generation
# 'sample' ships with every new Cloudinary account; substitute any public_id you own
thumbnail_url = Cloudinary::Utils.cloudinary_url(
"sample",
width: 200,
height: 200,
crop: "thumb",
gravity: "auto", # focus on the most interesting region; use "face" for people photos
fetch_format: "auto", # f_auto: best format for the requesting browser
quality: "auto" # q_auto: perceptual quality tuning
)
puts thumbnail_url
# https://res.cloudinary.com/<cloud>/image/upload/c_thumb,f_auto,g_auto,h_200,q_auto,w_200/sampleURLs are HTTPS by default — no secure: true needed. Pass secure: false for
http://.
In a Rails view, cl_image_tag takes the same options and renders a full <img> tag;
see Use with Rails.
Each component runs on the output of the previous one. Pass an array to transformation::
# A text overlay needs no second asset; to overlay an image instead, pass
# overlay: "<public_id of an image in your account>".
banner_url = Cloudinary::Utils.cloudinary_url(
"sample",
transformation: [
{ width: 1280, height: 720, crop: "fill", gravity: "auto" },
{
overlay: { font_family: "Arial", font_size: 64, font_weight: "bold", text: "SALE" },
color: "white",
gravity: "south_east",
x: 24,
y: 24
},
{ fetch_format: "auto", quality: "auto" }
]
)
puts banner_url
# .../image/upload/c_fill,g_auto,h_720,w_1280/co_white,g_south_east,l_text:Arial_64_bold:SALE,x_24,y_24/f_auto,q_auto/sampleReordering components changes the output. When matching eagerly generated versions, the serialized transformation string must match exactly.
Server-supported generative transformations (background removal, generative fill, and
similar) can be expressed as transformation strings — this gem serializes them
generically via effect: or raw_transformation:, without dedicated typed builders:
Cloudinary::Utils.cloudinary_url("sample", effect: "background_removal")
# .../image/upload/e_background_removal/sampleTheir availability is account- and plan-dependent; verify against https://cloudinary.com/documentation/generative_ai_transformations.md before relying on one.
- The same URL is served from CDN cache; a new transformation means a new URL.
- To bust stale caches after re-uploading the same
public_id, deliver with the assetversionfrom the upload response:
Cloudinary::Utils.cloudinary_url(result["public_id"], version: result["version"])
# .../image/upload/v1787584957/examples/uploaded-sample- Generated URLs carry an
?_a=SDK-analytics parameter. It does not affect delivery or caching; passanalytics: falseto omit it. - A
public_idcontaining a slash with no known version gets a/v1/placeholder segment (.../image/upload/v1/folder/name.jpg). This is expected and delivers correctly; pass the realversionwhen you have it.
Must supply cloud_name in tag or in configuration— URL building still needs acloud_name; see Configure Cloudinary.- 401 on a delivery URL from a freshly provisioned cloud — delivery is IP-locked until the cloud is claimed, not a URL problem. See Get Cloudinary credentials.
- 404 on a URL that looks right — the
public_iddoes not exist, or it was uploaded as a differentresource_type. An asset uploaded asrawis not deliverable as an image.
- Runnable example:
examples/transform-and-deliver-image.rb - Transform and deliver a video
- Every transformation parameter and its accepted values: Transformation reference
- Image manipulation guide