Whether your web application supports user uploaded images, you deliver static images, or you display profile pictures from social networks, you probably need to manipulate them to fit the graphic design of your Web site or mobile application.
Cloudinary allows you to easily transform your images on-the-fly to any required format, style and dimension, and also optimizes images for minimal file size alongside high visual quality for an improved user experience and minimal bandwidth. You can do all of this by implementing dynamic image transformation and delivery URLs. You can change the required transformations at any time. All transformed images are created on-demand (lazily) and delivered to your users through a fast CDN with optimized caching.
For example, you can resize and crop images, deliver them using the image format that fits your needs, and/or apply a variety of filters and effects. You can also use our smart cropping techniques, including face-detection or auto-gravity for cropping based on the most relevant parts of uploaded photos. For complex transformations, you can use the Management Console or Admin API for defining named transformations and even run a set of chained transformations on your images. You can also use the Management Console to view delivery usage reports and optimization insights.
This page teaches you how Cloudinary transformations work and provides detailed descriptions and use‑case examples for commonly-used transformations.
Your account's pricing plan is in part dependent on the total number of
transformation operations performed during a billing cycle. These are primarily counted when Cloudinary generates a new 'derived resource' from an asset based on a transformation URL. For complete details on how transformations are counted, see
Transformation Counts.
The following dynamic URL with on-the-fly image transformation crops an image to a 400x400 circular thumbnail while automatically focusing on the face, and then scales down the result to a width of 200 pixels. Below you can see the original image (scaled down) and the dynamically created face detection based thumbnail.

Ruby:
cl_image_tag("lady.jpg", :transformation=>[
{:width=>400, :height=>400, :gravity=>"face", :radius=>"max", :crop=>"crop"},
{:width=>200, :crop=>"scale"}
])
PHP:
cl_image_tag("lady.jpg", array("transformation"=>array(
array("width"=>400, "height"=>400, "gravity"=>"face", "radius"=>"max", "crop"=>"crop"),
array("width"=>200, "crop"=>"scale")
)))
Python:
CloudinaryImage("lady.jpg").image(transformation=[
{'width': 400, 'height': 400, 'gravity': "face", 'radius': "max", 'crop': "crop"},
{'width': 200, 'crop': "scale"}
])
Node.js:
cloudinary.image("lady.jpg", {transformation: [
{width: 400, height: 400, gravity: "face", radius: "max", crop: "crop"},
{width: 200, crop: "scale"}
]})
Java:
cloudinary.url().transformation(new Transformation()
.width(400).height(400).gravity("face").radius("max").crop("crop").chain()
.width(200).crop("scale")).imageTag("lady.jpg");
JS:
cloudinary.imageTag('lady.jpg', {transformation: [
{width: 400, height: 400, gravity: "face", radius: "max", crop: "crop"},
{width: 200, crop: "scale"}
]}).toHtml();
jQuery:
$.cloudinary.image("lady.jpg", {transformation: [
{width: 400, height: 400, gravity: "face", radius: "max", crop: "crop"},
{width: 200, crop: "scale"}
]})
React:
<Image publicId="lady.jpg" >
<Transformation width="400" height="400" gravity="face" radius="max" crop="crop" />
<Transformation width="200" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="lady.jpg" >
<cld-transformation width="400" height="400" gravity="face" radius="max" crop="crop" />
<cld-transformation width="200" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="lady.jpg" >
<cl-transformation width="400" height="400" gravity="face" radius="max" crop="crop">
</cl-transformation>
<cl-transformation width="200" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(400).Height(400).Gravity("face").Radius("max").Crop("crop").Chain()
.Width(200).Crop("scale")).BuildImageTag("lady.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.width(400).height(400).gravity("face").radius("max").crop("crop").chain()
.width(200).crop("scale")).generate("lady.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setWidth(400).setHeight(400).setGravity("face").setRadius("max").setCrop("crop").chain()
.setWidth(200).setCrop("scale")).generate("lady.jpg")!, cloudinary: cloudinary)
- Watch the Transformation Basics video tutorial to see how these dynamic transformation URLs work.
- The Transformation URL API Reference details all transformation parameters available for both images and videos. Icons indicate which parameters are supported for each asset type.
Cloudinary's client libraries (SDKs) take care of the transformation URL building for you, and simplify the integration even further. They allow you to continue working in your preferred developer framework and provide helper methods to simplify building image tags and image transformation URLs: Rails, PHP, Django, JavaScript, jQuery, Node.js, .NET, Java, Angular, Javascript, React, Vue.js, iOS, Scala and Android.
Accessing media assets is done using simple delivery HTTP or HTTPS URLs which are then delivered to users via a worldwide fast CDN. The URL contains the Public ID of the requested asset plus any optional transformation parameters. The public ID is the unique identifier of the asset and is either specified when uploading the asset to your Cloudinary account, or automatically assigned by Cloudinary (see Upload images for more details on the various options for specifying the public ID).
The default Cloudinary asset delivery URL has the following structure:
https://res.cloudinary.com/<cloud_name>/<asset_type>/<delivery_type>/<transformations>/<version>/<public_id>.<format>
Where:
cloud_name
- The name of your Cloudinary account, a unique public identifier for URL building and API access.
asset_type
- (optional) The type of asset to deliver. Default: image
. Valid values: image
, raw
, or video
.
- The
image
type includes still image and photo formats, animated images, PDFs, layered files, such as TIFF and PSD, and others.
- The
video
type includes video and audio files.
- The
raw
type includes any file uploaded to Cloudinary that does not fit in one of the above categories. In general, transformations cannot be performed on raw
assets, but they can be delivered as-is for download purposes, or in some cases, they may be used in conjunction with your image or video transformations.
delivery_type
- (optional) The storage or delivery type. Default: upload
. For details on all possible types, see Delivery types.
transformations
(optional) One or more transformation parameters in a single component, or a set of chained transformations in multiple components. When the transformation URL is first accessed, the derived media file is created on-the-fly and delivered to your user. The derived file is also cached on the CDN and is immediately available to all subsequent users requesting the same asset.
version
- (optional) You can add the version to your delivery URL to bypass the cached version on the CDN and force delivery of the latest resource (in the case that a resource has been overwritten with a newer file). For simplicity, the version component is generally not included in the example URLs on this page. For details, see Asset versions.
public_id
- The unique identifier of the resource, including the folder structure if relevant.
format
- (optional) The file extension of the requested delivery format for the resource. Default: The originally uploaded format or the format determined by f_auto, when used.
Therefore, in the most general case of delivering an image that has been uploaded to your Cloudinary account, the delivery URL is given as:
https://res.cloudinary.com/<cloud_name>/image/upload/<public_id>.<format>
For example, displaying the image with a public ID of sample
uploaded to Cloudinary's demo
account in jpg
format:
Ruby:
cl_image_tag("sample.jpg")
PHP:
cl_image_tag("sample.jpg")
Python:
CloudinaryImage("sample.jpg").image()
Node.js:
cloudinary.image("sample.jpg")
Java:
cloudinary.url().imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg').toHtml();
jQuery:
$.cloudinary.image("sample.jpg")
React:
<Image publicId="sample.jpg" >
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().generate("sample.jpg")!, cloudinary: cloudinary)
Any transformation (manipulation) instructions can be added before the public ID in the delivery URL. When the URL is first accessed, the derived image is created on-the-fly and delivered to your user. The derived image is also cached on the CDN and is immediately available to all subsequent users requesting the same image.
The following shows an example of delivering an image with transformation parameters, where the image with a public ID of sample
is cropped to a width of 300 pixels and a height of 200 pixels, and delivered in JPEG format:
Ruby:
cl_image_tag("sample.jpg", :width=>300, :height=>200, :crop=>"crop")
PHP:
cl_image_tag("sample.jpg", array("width"=>300, "height"=>200, "crop"=>"crop"))
Python:
CloudinaryImage("sample.jpg").image(width=300, height=200, crop="crop")
Node.js:
cloudinary.image("sample.jpg", {width: 300, height: 200, crop: "crop"})
Java:
cloudinary.url().transformation(new Transformation().width(300).height(200).crop("crop")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 300, height: 200, crop: "crop"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 300, height: 200, crop: "crop"})
React:
<Image publicId="sample.jpg" >
<Transformation width="300" height="200" crop="crop" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="300" height="200" crop="crop" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="300" height="200" crop="crop">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(300).Height(200).Crop("crop")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(300).height(200).crop("crop")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(300).setHeight(200).setCrop("crop")).generate("sample.jpg")!, cloudinary: cloudinary)
You can also use shortcut URLs when specifically delivering image files using the default upload
type. With Cloudinary’s Root Path URL feature, the resource type
and type
parameters can be omitted from the URL (they automatically default to the values 'image' and 'upload' respectively). For example, the Root Path shortcut delivery URL for the cropped image above is:
https://res.cloudinary.com/demo/w_300,h_200,c_crop/sample.jpg
The rest of this page describes the various types of available transformation and delivery options, including many detailed use-case examples. See the Transformation URL API Reference for the complete list of available transformation parameters, syntax, and examples.
The delivery type element of the URL provides an indication about the way the asset will be delivered, although in most cases, the delivery type value is determined at the time that the asset is stored in your account.
The following delivery type values are supported:
Delivery type |
Description |
Learn more |
upload |
The default delivery type for uploaded assets. In most cases, this delivery type indicates that the asset is publicly available. However, there are options you can use to restrict access to assets with an upload delivery type. This includes strict transformations and access mode settings) |
Upload API |
private |
The URL for the original asset can be accessed only with a signed URL. Transformed versions of the asset are publicly available (unless strict transformations are also defined). |
Uploading private assets |
authenticated |
Both original and transformed versions of the asset can be accessed only with a signed URL or an authentication token. |
Uploading authenticated assets Delivering authenticated assets |
fetch |
Enables transforming and delivering remote images on-the-fly. |
Fetch remote images |
facebook twitter twitter_name gravatar |
Fetches a profile picture from Facebook, Twitter, or other specified social delivery type based on a specified ID or name. |
Social media profile pictures |
youtube hulu vimeo animoto worldstarhiphop dailymotion |
Delivers a thumbnail image generated from the specified video from a public video site. |
Fetching thumbnails of public videos |
multi |
Enables you to deliver a single animated image (GIF, PNG or WebP) from all image assets that have been assigned a specified tag. |
Multi method Creating animated images |
text |
Enables you to generate an image in your account from a specified textual string along with style parameters for use as an image overlay. |
Text method |
asset |
Relevant only for the Ruby on Rails SDK. Delivers files that were uploaded using the sync_static command. |
Static files |
list |
Generates a list of resources with a specified tag. Note: This isn't a delivery type in the classic sense, in that it doesn't relate to an individual asset. However, to use this feature, you specify list in the delivery type element of the URL. |
Client-side resource lists |
You can search for assets by delivery type using the Advanced Search in the Media Library. The most common types can be selected directly in the
Type section of the
Tags & Metadata search tab. All other types can be selected from the
More types list.
There are two types of transformation parameters:
- Action parameters: Parameters that perform a specific transformation on the asset.
- Qualifier parameters: Parameters that do not perform an action on their own, but rather alter the default behavior or otherwise adjust the outcome of the corresponding action parameter.
It's best practice to include only one action parameter per URL component.
If you want to apply multiple actions in a single transformation URL, apply them in separate chained components, where each action is performed on the result of the previous one.
In contrast, qualifier parameters must be included in the component with the action parameter they qualify.
- Most qualifiers are optional, meaning the related action parameter can be used independently, but you can add optional qualifiers to modify the default behavior.
- In some cases, an action parameter requires one or more qualifiers to fully define the transformation behavior.
- There are a few parameters that can be used independently as action parameters, but can also be used in other scenarios as a qualifier for another action.
Transformation flags alter default transformation behavior. In some cases, they alter the default behavior of the transformation URL as a whole. In other cases, they alter the behavior of one or more specific transformation parameters that must be used together in the same URL component.
In general, tens of flags are available that can alter delivery and format, cropping and positioning, metadata and color profiles, and overlays, PDFs, and text behaviors.
For example:
fl_attachment alters the normal behavior of the overall transformation. Instead of delivering an image or video in a web page, it causes the transformed media file as an attachment. This flag can be used independently.
fl_relative modifies the way overlay resize parameters are evaluated. This flag can only be used in conjunction with the overlay (l_publicid
) parameter.
For details on all available transformation flags, see the flag section of the Transformation Reference.
Cloudinary supports delivering media assets using HTTPS URLs. The process for creating HTTPS delivery URLs is identical to creating HTTP URLs, with only the URL protocol changing. When using one of Cloudinary's framework SDKs, you can generate HTTPS URLs by setting the secure
parameter to true
, either globally (e.g., in the CLOUDINARY_URL environment variable) or locally in each call. For example, delivering the sample
image with HTTPS:
Ruby:
cl_image_tag("sample.jpg", :secure=>true)
PHP:
cl_image_tag("sample.jpg", array("secure"=>true))
Python:
CloudinaryImage("sample.jpg").image(secure=True)
Node.js:
cloudinary.image("sample.jpg", {secure: true})
Java:
cloudinary.url().secure(true).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {secure: true}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {secure: true})
React:
<Image publicId="sample.jpg" secure="true">
</Image>
Vue.js:
<cld-image publicId="sample.jpg" secure="true">
</cld-image>
Angular:
<cl-image public-id="sample.jpg" secure="true">
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Secure(true).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().secure(true).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().generate("sample.jpg")!, cloudinary: cloudinary)
For more information on using HTTPS to deliver your media assets, see the article on Why isn't everyone using HTTPS and how to do it with Cloudinary.
Some transformations with multiple options offer two alternative syntaxes for defining the option values:
- Verbose, unordered: Each option of the transformation (whether required or optional) is specified in the verbose format
name_value
and each option is separated by a colon (:
). The options can be specified in any order, and you only need to include those that you want (or are required) to define.
For example, the progressbar
effect supports the type
, color
, and width
parameters, but you can specify them in a different order: e_progressbar:width_5:type_frame:color_FF0000
.
You can also choose to specify only the options for which you don't want to use default values and default values will be applied for the others. For example: e_progressbar:width_5
will generate a progressbar with a width of 5
pixels, while applying the default values for type
and frame
.
- Non-verbose, ordered: Transformation options are specified only by values, and must be entered in the pre-defined option order for that transformation. All values from the syntax to the left of the value you want to supply must also be entered.
For example, if you only need to change the default behavior of the second option, you must still specify the value to use for the first option: e_progressbar:bar:FF0000
applies the bar
(default) type and a custom color, along with the default width of 10
pixels.
Transformations that support both verbose and non-verbose URL syntax are indicated as such in the Transformation Reference. SDKs always output the verbose syntax.
In addition to changing the appearance of your media assets by transforming them, you can also use Cloudinary URLs and a variety of parameters to control how they are delivered:
- Optimizations - Deliver your media assets with the smallest possible file size while maintaining visual quality, saving bandwidth and improving performance for your website.
- Responsive images - Deliver your images to perfectly fit any device, window size, orientation, or resolution at any pixel density (DPR). Upload a single high resolution image and let Cloudinary automatically transform it.
- Remotely fetched media - Grab media assets from anywhere on the web, including support for on-the-fly manipulation and optimized delivery via a CDN.
- Paged and layered media - Deliver content from assets with multiple pages or layers such as PDFs or Photoshop files, including options for delivering or transforming only selected pages or layers.
- Access control - Control who can access your media, both the originals and transformed assets.
Accessing uploaded images or their derived transformations is done using simple URLs that you can use as the 'src' of the 'img' tags in your HTML code or Javascript functions. URLs for accessing resources contain the resource kind, the Public ID of the resource, and optional version and transformation parameters. You can also use Cloudinary’s web framework SDKs to aid you in adding images to your web application and simplify the creation of transformation URLs and embedding HTML image tags. Cloudinary offers two main helper methods in this regard:
The Cloudinary URL helper method (e.g., cloudinary_url
in Ruby on Rails) automatically generates the image source URL for use as the 'src' of the 'img' tags in your HTML code or Javascript functions. For example, using the URL helper method to return the URL of the sample
image, scaled to a width of 300 pixels and a height of 100 pixels:
Ruby:
cloudinary_url("sample.jpg", :width=>300, :height=>100, :crop=>"scale")
PHP:
Cloudinary::cloudinary_url("sample.jpg", array("width"=>300, "height"=>100, "crop"=>"scale"))
Python:
cloudinary.utils.cloudinary_url("sample.jpg", width=300, height=100, crop="scale")
Node.js:
cloudinary.url("sample.jpg", {width: 300, height: 100, crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(300).height(100).crop("scale")).generate("sample.jpg")
JS:
cloudinary.url('sample.jpg', {width: 300, height: 100, crop: "scale"});
jQuery:
$.cloudinary.url("sample.jpg", {width: 300, height: 100, crop: "scale"})
React:
cloudinary.url('sample.jpg', {width: 300, height: 100, crop: "scale"});
Vue.js:
cloudinary.url('sample.jpg', {width: 300, height: 100, crop: "scale"});
Angular:
cloudinary.url('sample.jpg', {width: 300, height: 100, crop: "scale"});
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(300).Height(100).Crop("scale")).BuildUrl("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(300).height(100).crop("scale")).generate("sample.jpg");
iOS:
cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(300).setHeight(100).setCrop("scale")).generate("sample.jpg")
The Cloudinary Image Tag helper method (e.g., cl_image_tag
in Ruby on Rails) automatically generates an HTML image tag including the image source URL. For example, using the Image Tag helper method to create an HTML image tag for the sample
image, scaled to a width of 300 pixels and a height of 100 pixels:
Ruby:
cl_image_tag("sample.jpg", :width=>300, :height=>100, :crop=>"scale")
PHP:
cl_image_tag("sample.jpg", array("width"=>300, "height"=>100, "crop"=>"scale"))
Python:
CloudinaryImage("sample.jpg").image(width=300, height=100, crop="scale")
Node.js:
cloudinary.image("sample.jpg", {width: 300, height: 100, crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(300).height(100).crop("scale")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 300, height: 100, crop: "scale"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 300, height: 100, crop: "scale"})
React:
<Image publicId="sample.jpg" >
<Transformation width="300" height="100" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="300" height="100" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="300" height="100" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(300).Height(100).Crop("scale")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(300).height(100).crop("scale")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(300).setHeight(100).setCrop("scale")).generate("sample.jpg")!, cloudinary: cloudinary)
The Cloudinary Image Tag helper method allows you to not only specify any Cloudinary transformations parameters, but also to specify regular HTML image tag attributes (e.g., alt, title, width, height). For example, using the Image Tag helper method to create an HTML image tag for the sample
image, with the 'alt' attribute set to "A sample photo" and the 'className' attribute set to "Samples":
Ruby:
cl_image_tag("sample.jpg", :alt=>"A sample photo", :className=>"Samples")
PHP:
cl_image_tag("sample.jpg", array("alt"=>"A sample photo", "className"=>"Samples"))
Python:
CloudinaryImage("sample.jpg").image(alt="A sample photo", className="Samples")
Node.js:
cloudinary.image("sample.jpg", {alt: "A sample photo", className: "Samples"})
Java:
cloudinary.url().imageTag("sample.jpg", ObjectUtils.asMap("alt","A sample photo","className","Samples"));
JS:
cl.imageTag('sample.jpg', {alt: "A sample photo", className: "Samples"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {alt: "A sample photo", className: "Samples"})
React:
<Image publicId="sample.jpg" alt="A sample photo" className="Samples">
</Image>
Vue.js:
<CLDImage publicId="sample.jpg" alt="A sample photo" className="Samples">
</CLDImage>
Angular:
<cl-image public-id="sample.jpg" alt="A sample photo" className="Samples">
</cl-image>
.NET:
@Model.Cloudinary.Api.UrlImgUp.BuildImageTag("sample.jpg", new CloudinaryDotNet.StringDictionary("alt=A sample photo", "className=Samples"));
In general, when using an SDK, you will probably take advantage of the SDK parameter names for improved readability and maintenance of your code. However, you can also optionally pass a
raw transformation parameter, whose value is a literal
URL transformation definition. Note that the string you pass as the raw transformation value will be appended as is (with no processing or validation) to the
end of any other transformation parameters passed in the same component of the transformation chain.
For example:
Ruby:
cl_image_tag("flower.jpg",
:transformation=>[{:raw_transformation=> "o_90,w_1000,c_fill,g_south_east/l_my_image,fl_relative,w_1.0"}])
PHP:
cl_image_tag("sample.jpg",
array("raw_transformation" => "w_400,c_pad"));
Python:
CloudinaryImage("sample.jpg").image(
transformation=[{"raw_transformation":"w_400,c_pad"}])
Node.js:
cloudinary.image("sample.jpg", { transformation: { raw_transformation: "w_400,c_pad" }})
Java:
<cl:image src="sample.jpg" raw_transformation="w_100,h_150,c_fill"/>
cloudinary.url()
.transformation(new Transformation().rawTransformation("w_100,h_150,c_fill"))
.imageTag("sample.jpg");
JS:
cl.imageTag("sample.jpg", { raw_transformation: "w_400,c_pad" }}).toHtml();
jQuery:
$.cloudinary.imageTag("sample.jpg", { raw_transformation: "w_400,c_pad" }}).toHtml();
React:
<Image publicId="mypic">
<Transformation rawTransformation="h_150,w_150,c_fill,e_sepia,r_20" />
</Image>
Vue.js:
<CLDImage publicId="sample.jpg" rawTransformation="w_150,h_150,c_fill">
</CLDImage>
Angular:
<cl-image
public-id="mypic"
class="thumbnail inline"
format="jpg"
raw-transformation="w_150,h_150,c_fill">
</cl-image>
.NET:
@Model.Cloudinary.Api.UrlImgUp.Transform(
new Transformation().RawTransformation("w_100,h_150,c_fill")).BuildImageTag("sample.jpg");
For more information on these SDK helper methods, see the documentation for the relevant framework: Ruby on Rails, PHP, Django, Node.js, Java, .NET, Angular, Javascript, React, Vue.js, iOS, Scala and Android.
Images can be uploaded to Cloudinary in various formats (input formats), and you can easily convert these images to other formats for displaying in your web site or application (output formats). Examples of situations where you might want to change the delivered image format:
- Delivering JPEGs for photos that you want to load quickly (or WebP if your users are on a Chrome browser or on a mobile app you control).
- Delivering a GIF if the image contains a drawing with only a few colors.
- Delivering a PNG (24 bit) for high quality illustrations with a transparent background.
- Delivering an image where the original format is not supported for delivery by the browser. For example, you could deliver a Photoshop (.psd) image as a JPG.
To deliver images in a different format simply specify the new format as the file extension of the delivery URL. When using our SDKs you can either specify the new format as an extension to the resource name or use the format
parameter.
For example, to display a GIF version of the uploaded sample
JPEG file:
Ruby:
cl_image_tag("sample.gif")
PHP:
cl_image_tag("sample.gif")
Python:
CloudinaryImage("sample.gif").image()
Node.js:
cloudinary.image("sample.gif")
Java:
cloudinary.url().imageTag("sample.gif");
JS:
cloudinary.imageTag('sample.gif').toHtml();
jQuery:
$.cloudinary.image("sample.gif")
React:
<Image publicId="sample.gif" >
</Image>
Vue.js:
<cld-image publicId="sample.gif" >
</cld-image>
Angular:
<cl-image public-id="sample.gif" >
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.BuildImageTag("sample.gif")
Android:
MediaManager.get().url().generate("sample.gif");
iOS:
imageView.cldSetImage(cloudinary.createUrl().generate("sample.gif")!, cloudinary: cloudinary)
You can easily combine other image transformations with format conversion. Just make sure the format you use is supported for transformations, as per the table above. For example, to deliver a scaled down 150x100 GIF version of the sample
image:
Ruby:
cl_image_tag("sample.gif", :width=>150, :height=>100, :crop=>"scale")
PHP:
cl_image_tag("sample.gif", array("width"=>150, "height"=>100, "crop"=>"scale"))
Python:
CloudinaryImage("sample.gif").image(width=150, height=100, crop="scale")
Node.js:
cloudinary.image("sample.gif", {width: 150, height: 100, crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(150).height(100).crop("scale")).imageTag("sample.gif");
JS:
cloudinary.imageTag('sample.gif', {width: 150, height: 100, crop: "scale"}).toHtml();
jQuery:
$.cloudinary.image("sample.gif", {width: 150, height: 100, crop: "scale"})
React:
<Image publicId="sample.gif" >
<Transformation width="150" height="100" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="sample.gif" >
<cld-transformation width="150" height="100" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="sample.gif" >
<cl-transformation width="150" height="100" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(100).Crop("scale")).BuildImageTag("sample.gif")
Android:
MediaManager.get().url().transformation(new Transformation().width(150).height(100).crop("scale")).generate("sample.gif");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setHeight(100).setCrop("scale")).generate("sample.gif")!, cloudinary: cloudinary)
- If the file extension is omitted from the delivery URL then the file is delivered in the originally uploaded format.
- Only the first 100 pages are included in the new file when converting from one multi-page or multi-layer image format (PDF, GIF, WebP, TIFF, PSD) to another.
The table below summarizes the supported format types.
Format |
Extensions |
Supported for Upload 1 |
Supported for Transformations 2 |
AI (Adobe Illustrator) |
.ai |
Yes |
Yes |
animated GIF |
.gif |
Yes |
Yes |
animated WebP |
.webp |
Yes |
Yes |
AVIF |
.avif |
Yes |
Yes 9 |
BMP |
.bmp |
Yes |
Yes |
DjVu |
.djvu |
Yes |
No |
EPS (Encapsulated PostScript) |
.ps, .ept, .eps, .eps3 |
Yes |
Yes |
FBX (Filmbox) |
.fbx |
Yes |
Yes 6 |
FLIF (Free Lossless Image Format) |
.flif |
Yes |
Yes |
GIF |
.gif |
Yes |
Yes |
GLB (Binary glTF) |
.glb |
Yes 7 |
No 8 |
glTF (GL Transmission Format) |
.gltf |
Yes |
Yes 6 |
HEIF |
.heif, .heic |
Yes |
Yes |
ICO |
.ico |
Yes |
Yes |
InDesign |
.indd |
Yes |
Yes 3 |
JPEG |
.jpg, .jpe, .jpeg |
Yes |
Yes |
JPEG 2000 |
.jp2 4 |
Yes |
Yes |
JPEG XR (JPEG eXtended Range) |
.wdp, .jxr, .hdp |
Yes |
Yes |
PDF |
.pdf |
Yes |
Yes |
PNG |
.png |
Yes |
Yes |
PSD (PhotoShop Document) |
.psd |
Yes |
Yes 5 |
Raw image files |
.arw, .cr2 |
Yes |
No |
SVG |
.svg |
Yes |
Yes |
TARGA (Truevision TGA) |
.tga |
Yes |
Yes |
TIFF |
.tif, .tiff |
Yes |
Yes |
USDZ |
.usdz |
Yes 7 |
No 8 |
WebP |
.webp |
Yes |
Yes |
- If a format is supported only for upload, then the delivery URL enables a user to download the original file in its original format, but you cannot apply transformation parameters.
- If a format is supported for transformations, but the browser doesn't support displaying that format, you can either provide the transformation URL with the original format to enable users to download the file, or you can provide the URL with a different delivery format specified. In that case, Cloudinary applies the transformation to the original format and then converts the image to the requested format for delivery. For example, you could provide a transformation URL for a PhotoShop (.psd) image stored in your account and specify
jpg
as the delivery format to display the resulting transformation in the browser.
- You can transform an InDesign file if you deliver it as an image format, such as
jpg
or png
, but you cannot deliver an indd
file with transformations.
- By default, when you request a
jp2
image with a quality value less than 90, chroma sub-sampling (420) is automatically applied using Kakadu. You can also explicitly request chroma sub-sampling as part of your quality
parameter. For example: q_90>:420
.
- All layers are flattened into a single image if no
page
parameter is specified.
- The 3D format types are uploaded as a zip file. Some transformations, such as converting to a video or image, are supported on the bundle as a whole. No transformations are currently supported on its contained assets. For further information see Transformations on 3D models.
- GLB and USDZ files can only be uploaded as raw files.
- Transformations cannot be applied to GLB or USDZ files, but you can deliver a glTF file as a GLB file or USDZ file.
- Support for AVIF is currently in Beta, with some known limitations. Images converted to AVIF from other formats use additional quota.
Another option for changing the format is to explicitly call the fetch_format
parameter (f
in URLs). This can be useful in situations where you cannot change the file extension, for example, when fetching remote images that already have a different file extension (format) as part of their URLs.
For example, to fetch a remote image from Wikimedia in JPEG format, and deliver the image in PNG format (also scaled down to a width of 400 pixels):
Ruby:
cl_image_tag("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg", :width=>400, :crop=>"scale", :format=>"png", :type=>"fetch")
PHP:
cl_image_tag("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg", array("width"=>400, "crop"=>"scale", "format"=>"png", "type"=>"fetch"))
Python:
CloudinaryImage("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg").image(width=400, crop="scale", format="png", type="fetch")
Node.js:
cloudinary.image("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg", {width: 400, crop: "scale", format: "png", type: "fetch"})
Java:
cloudinary.url().transformation(new Transformation().width(400).crop("scale")).format("png").type("fetch").imageTag("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg");
JS:
cloudinary.imageTag('https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg', {width: 400, crop: "scale", format: "png", type: "fetch"}).toHtml();
jQuery:
$.cloudinary.image("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg", {width: 400, crop: "scale", format: "png", type: "fetch"})
React:
<Image publicId="https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg" format="png" type="fetch">
<Transformation width="400" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg" format="png" type="fetch">
<cld-transformation width="400" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg" format="png" type="fetch">
<cl-transformation width="400" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(400).Crop("scale")).Format("png").Action("fetch").BuildImageTag("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(400).crop("scale")).format("png").type("fetch").generate("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setFormat("png").setType( "fetch").setTransformation(CLDTransformation().setWidth(400).setCrop("scale")).generate("https://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg")!, cloudinary: cloudinary)
There are a lot of formats for encoding images, with some formats better than others at compression and reducing the file size without impairing visual quality. Since different browsers support different image formats, the best solution to save bandwidth and optimize delivery time would be to deliver the best format according to the browser used by each of your visitors.
The fetch_format
parameter can be set to auto (f_auto
in URLs) in order to perform automatic format selection based on the requesting browser. For example, with the automatic format feature, in most cases Chrome users would receive a WebP (.webp), Internet Explorer users would receive a JPEG-XR (.jxr), and Safari users would receive a JPEG-2000 (.jp2). If a browser does not support any of these formats then the image is delivered in the format specified by the file extension.
For example, the uploaded jpg image named sample
scaled down to a width of 500 pixels and delivered as WebP to Chrome browsers (22.4 KB), JPEG-XR to Internet Explorer browsers (48 KB), or as a regular JPEG (57.5 KB) to browsers that support neither format:
Ruby:
cl_image_tag("sample.jpg", :width=>500, :fetch_format=>:auto, :crop=>"scale")
PHP:
cl_image_tag("sample.jpg", array("width"=>500, "fetch_format"=>"auto", "crop"=>"scale"))
Python:
CloudinaryImage("sample.jpg").image(width=500, fetch_format="auto", crop="scale")
Node.js:
cloudinary.image("sample.jpg", {width: 500, fetch_format: "auto", crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(500).fetchFormat("auto").crop("scale")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 500, fetchFormat: "auto", crop: "scale"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 500, fetch_format: "auto", crop: "scale"})
React:
<Image publicId="sample.jpg" >
<Transformation width="500" fetchFormat="auto" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="500" fetchFormat="auto" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="500" fetch-format="auto" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(500).FetchFormat("auto").Crop("scale")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(500).fetchFormat("auto").crop("scale")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(500).setFetchFormat("auto").setCrop("scale")).generate("sample.jpg")!, cloudinary: cloudinary)
- When automatic format (
f_auto
) is used together with automatic quality (q_auto
), the PNG format may be selected when the automatic quality algorithm decides that it better fits the specific image. This allows delivering better looking and economical image files.
- JPG-2000 is included as an option for
f_auto
on Cloudinary accounts created after October 2019. To enable this option for older accounts, contact support.
- When
f_auto
is used together with q_auto
for JPEG images and the automatic quality algorithm decides that no chroma subsampling should be performed, the JPEG format is selected instead of WebP. This behavior is needed because the lossy WebP format always performs chroma subsampling, which might result in a lower visual quality for some images.
- Setting the
any_format
flag together with automatic quality (q_auto,fl_any_format
) but without setting f_auto
, will also allow switching to PNG8 encoding if the quality algorithm decides that it's more efficient.
- If
f_auto
is used to deliver an image that contains transparency, and the requesting browser does not support WebP or JPEG-XR, then the image is delivered in PNG format instead of the JPEG format.
You can resize and crop images in order to match the graphic design of your web site or mobile application. Whether images are uploaded in your server-side code or by your users, the original hi-res images are stored in the cloud for further processing and management. You can then dynamically create multiple resized, cropped and manipulated images on-the-fly and deliver them via dynamic URLs.
When changing the dimensions of an uploaded image by setting the image's height, width, and/or aspect ratio you need to decide how to resize or crop the image to fit into the requested size. Use the crop
parameter for selecting the resize/crop mode (c
in URLs). Cloudinary supports the following image resize/crop modes:
Resize/crop mode |
Behavior |
Resize modes |
These modes adjust the size of the delivered image without cropping out any elements of the original image. |
scale |
Resizes the image to the specified dimensions without necessarily retaining the original aspect ratio. |
fit |
Resizes the image to fit inside the bounding box specified by the dimensions, maintaining the aspect ratio. |
limit |
Same as fit , but only scales down the image. |
mfit |
Same as fit , but only scales up the image. |
pad |
Resizes the image to fit inside the bounding box specified by the dimensions, maintaining the aspect ratio, and applies padding if the resized image does not fill the whole area. |
lpad |
Same as pad , but only scales down the image. |
mpad |
Same as pad , but only scales up the image. |
Cropping modes |
If the requested dimensions have a different aspect ratio than the original, these modes crop out part of the image. |
crop |
Extracts a region of the specified dimensions from the original image without first resizing it. |
fill |
Resizes the image to fill the specified dimensions without distortion. The image may be cropped as a result. |
lfill |
Same as fill , but only scales down the image. |
fill_pad |
Same as fill , but avoids excessive cropping by adding padding when needed. Supported only with automatic cropping. |
thumb |
Creates a thumbnail of the image with the specified dimensions, based on a specified gravity. Scaling may occur. |
Add-on resize and crop modes |
These modes adjust the size and/or crop the image using an add-on. |
imagga_scale |
Performs smart scaling, using the Imagga Crop and Scale add-on. |
imagga_crop |
Performs smart cropping, using the Imagga Crop and Scale add-on. |
When creating dynamic delivery URLs, if you specify only the width and/or height parameters, but no cropping mode (no
c_<mode>
), the image is
scaled to the new dimensions by default. However, there is no default cropping mode when using the Cloudinary SDK helper methods (see
Embedding images in web pages), so a cropping mode must be explicitly set.
Some of the cropping modes keep only a certain part of the original image in the resulting image. By default, the center of the image is kept in the crop, but this is not always ideal. To keep the parts of the image that are important to you, you can use the gravity parameter. For example, you can specify to keep faces, text, or certain objects in the crop, or gravitate towards an automatically-determined area of interest. You can also guide the crop towards areas of your image defined by compass points, for example, north
to keep the top part of the image, or south_east
to keep the bottom-right part. Additionally, if you know the coordinates of the area you want to keep, you can explicitly specify these.
You can set the target dimensions of your resized image by specifying width, height, and/or the target aspect ratio.
- Using an integer value for width or height sets the new dimension to that number in pixels. For example,
w_150
sets the width to exactly 150 pixels.
- Using a decimal value for width or height sets the new dimension as a multiple of the original dimension. For example,
w_0.5
sets the width to half the original width.
- Using
ih
or iw
as values sets the dimension to the initial height or initial width of the original image respectively. For example, w_iw
sets the width to the same value as the original width of the image. This may be useful when applying chained transformations or setting the dimensions of an overlay.
- Aspect ratios are specified as a decimal number, where 1.0 is a perfect square. For example,
ar_0.56
defines 9:16 portrait dimensions that would work well for most mobile phones.
In most cases, you will specify both width and height or width/height along with an aspect ratio to define the exact required dimensions. However, in rare cases, you may choose to specify only one of these 3 resize qualifiers, and Cloudinary will automatically determine the missing dimension as follows:
- If you provide only width or only height, then the other dimension is automatically calculated to deliver the original aspect ratio. For example, if your original asset is 400*600, then specifying
c_crop,w_200
is the same as specifying c_crop,w_200,h_300
. Supported for all resize and crop modes.
- If you provide only the aspect ratio: If
ar
> 1, the original width is maintained and the height is cropped to deliver the requested ratio. If ar
< 1, the original height is maintained, and the width is cropped accordingly. Supported for modes that support cropping out part of the image (crop, the fill modes, the pad modes, and thumb). Not supported for imagga_crop
.
If you want to resize only one dimension, and keep the other dimension at it's original size (rather than the automatic determination described above), you can specify only width or only height, and add the
fl_ignore_aspect_ratio flag qualifier.
The following examples show the same image resized to a width and height of 200 pixels, using different methods of cropping.
The original image is 640 x 426 pixels:
Resizing the image to 200 x 200 pixels, using crop, scale, fill and pad results in the following images:
c_crop,h_200,w_200
c_scale,h_200,w_200
c_fill,h_200,w_200
c_pad,h_200,w_200
The URL with the c_crop
transformation takes this form:
Ruby:
cl_image_tag("docs/models.jpg", :height=>200, :width=>200, :crop=>"crop")
PHP:
cl_image_tag("docs/models.jpg", array("height"=>200, "width"=>200, "crop"=>"crop"))
Python:
CloudinaryImage("docs/models.jpg").image(height=200, width=200, crop="crop")
Node.js:
cloudinary.image("docs/models.jpg", {height: 200, width: 200, crop: "crop"})
Java:
cloudinary.url().transformation(new Transformation().height(200).width(200).crop("crop")).imageTag("docs/models.jpg");
JS:
cloudinary.imageTag('docs/models.jpg', {height: 200, width: 200, crop: "crop"}).toHtml();
jQuery:
$.cloudinary.image("docs/models.jpg", {height: 200, width: 200, crop: "crop"})
React:
<Image publicId="docs/models.jpg" >
<Transformation height="200" width="200" crop="crop" />
</Image>
Vue.js:
<cld-image publicId="docs/models.jpg" >
<cld-transformation height="200" width="200" crop="crop" />
</cld-image>
Angular:
<cl-image public-id="docs/models.jpg" >
<cl-transformation height="200" width="200" crop="crop">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Height(200).Width(200).Crop("crop")).BuildImageTag("docs/models.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().height(200).width(200).crop("crop")).generate("docs/models.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setHeight(200).setWidth(200).setCrop("crop")).generate("docs/models.jpg")!, cloudinary: cloudinary)
The following sections explain how each of the crop modes behave.
Change the size of the image exactly to the given width and height without necessarily retaining the original aspect ratio: all original image parts are visible but might be stretched or shrunk. If only the width or height is given, then the image is scaled to the new dimension while retaining the original aspect ratio, unless you also include the ignore_aspect_ratio flag.
Examples of scaling the uploaded image named sample
:
Scaled to a width of 150 pixels (maintains the aspect ratio by default):
Ruby:
cl_image_tag("sample.jpg", :width=>150, :crop=>"scale")
PHP:
cl_image_tag("sample.jpg", array("width"=>150, "crop"=>"scale"))
Python:
CloudinaryImage("sample.jpg").image(width=150, crop="scale")
Node.js:
cloudinary.image("sample.jpg", {width: 150, crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(150).crop("scale")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 150, crop: "scale"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 150, crop: "scale"})
React:
<Image publicId="sample.jpg" >
<Transformation width="150" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="150" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="150" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Crop("scale")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(150).crop("scale")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setCrop("scale")).generate("sample.jpg")!, cloudinary: cloudinary)
Scaled to a width and height of 150 pixels without maintaining the aspect ratio:
Ruby:
cl_image_tag("sample.jpg", :width=>150, :height=>150, :crop=>"scale")
PHP:
cl_image_tag("sample.jpg", array("width"=>150, "height"=>150, "crop"=>"scale"))
Python:
CloudinaryImage("sample.jpg").image(width=150, height=150, crop="scale")
Node.js:
cloudinary.image("sample.jpg", {width: 150, height: 150, crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(150).height(150).crop("scale")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 150, height: 150, crop: "scale"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 150, height: 150, crop: "scale"})
React:
<Image publicId="sample.jpg" >
<Transformation width="150" height="150" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="150" height="150" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="150" height="150" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(150).Crop("scale")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(150).height(150).crop("scale")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setHeight(150).setCrop("scale")).generate("sample.jpg")!, cloudinary: cloudinary)
Scaled to a width of 25% (maintains the aspect ratio by default):
Ruby:
cl_image_tag("sample.jpg", :width=>0.25, :crop=>"scale")
PHP:
cl_image_tag("sample.jpg", array("width"=>"0.25", "crop"=>"scale"))
Python:
CloudinaryImage("sample.jpg").image(width="0.25", crop="scale")
Node.js:
cloudinary.image("sample.jpg", {width: "0.25", crop: "scale"})
Java:
cloudinary.url().transformation(new Transformation().width(0.25).crop("scale")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: "0.25", crop: "scale"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: "0.25", crop: "scale"})
React:
<Image publicId="sample.jpg" >
<Transformation width="0.25" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="0.25" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="0.25" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(0.25).Crop("scale")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(0.25).crop("scale")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(0.25).setCrop("scale")).generate("sample.jpg")!, cloudinary: cloudinary)
The image is resized so that it takes up as much space as possible within a bounding box defined by the given width and height parameters. The original aspect ratio is retained and all of the original image is visible.
For example, the uploaded image named sample
is resized to fit within a width and height of 250 pixels while retaining the aspect ratio:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :crop=>"fit")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "crop"=>"fit"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, crop="fit")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "fit"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).crop("fit")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, crop: "fit"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "fit"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" crop="fit" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" crop="fit" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" crop="fit">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Crop("fit")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).crop("fit")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setCrop("fit")).generate("sample.jpg")!, cloudinary: cloudinary)
Same as the fit
mode but only if the original image is larger than the given limit (width and height), in which case the image is scaled down so that it takes up as much space as possible within a bounding box defined by the given width and height parameters. The original aspect ratio is retained and all of the original image is visible. This mode doesn't scale up the image if your requested dimensions are larger than the original image's.
For example, the uploaded jpg image named sample
limited to a width and height of 250 pixels while retaining the aspect ratio:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :crop=>"limit")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "crop"=>"limit"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, crop="limit")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "limit"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).crop("limit")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, crop: "limit"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "limit"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" crop="limit" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" crop="limit" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" crop="limit">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Crop("limit")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).crop("limit")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setCrop("limit")).generate("sample.jpg")!, cloudinary: cloudinary)
Same as the fit
mode but only if the original image is smaller than the given minimum (width and height), in which case the image is scaled up so that it takes up as much space as possible within a bounding box defined by the given width and height parameters. The original aspect ratio is retained and all of the original image is visible. This mode doesn't scale down the image if your requested dimensions are smaller than the original image's.
For example, attempting to fit the uploaded image named sample
to a minimum width and height of 250 pixels while retaining the aspect ratio, results in delivering the original larger image:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :crop=>"mfit")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "crop"=>"mfit"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, crop="mfit")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "mfit"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).crop("mfit")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, crop: "mfit"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "mfit"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" crop="mfit" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" crop="mfit" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" crop="mfit">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Crop("mfit")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).crop("mfit")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setCrop("mfit")).generate("sample.jpg")!, cloudinary: cloudinary)
Resize the image to fill the given width and height while retaining the original aspect ratio and with all of the original image visible. If the proportions of the original image do not match the given width and height, padding is added to the image to reach the required size. You can also specify where the original image is placed by using the gravity parameter (set to center
by default), and specify the color of the background in the case that padding is added.
For example, the uploaded jpg image named sample
padded with a black background to a width and height of 250 pixels:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :background=>"black", :crop=>"pad")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "background"=>"black", "crop"=>"pad"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, background="black", crop="pad")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, background: "black", crop: "pad"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).background("black").crop("pad")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, background: "black", crop: "pad"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, background: "black", crop: "pad"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" background="black" crop="pad" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" background="black" crop="pad" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" background="black" crop="pad">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Background("black").Crop("pad")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).background("black").crop("pad")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setBackground("black").setCrop("pad")).generate("sample.jpg")!, cloudinary: cloudinary)
Same as the pad
mode but only if the original image is larger than the given limit (width and height), in which case the image is scaled down to fill the given width and height while retaining the original aspect ratio and with all of the original image visible. This mode doesn't scale up the image if your requested dimensions are bigger than the original image's. If the proportions of the original image do not match the given width and height, padding is added to the image to reach the required size. You can also specify where the original image is placed by using the gravity parameter (set to center
by default), and specify the color of the background in the case that padding is added.
For example, the uploaded jpg image named sample
limit padded with a green background to a width of 400 pixels and a height of 150 pixels:
Ruby:
cl_image_tag("sample.jpg", :width=>400, :height=>150, :background=>"green", :crop=>"lpad")
PHP:
cl_image_tag("sample.jpg", array("width"=>400, "height"=>150, "background"=>"green", "crop"=>"lpad"))
Python:
CloudinaryImage("sample.jpg").image(width=400, height=150, background="green", crop="lpad")
Node.js:
cloudinary.image("sample.jpg", {width: 400, height: 150, background: "green", crop: "lpad"})
Java:
cloudinary.url().transformation(new Transformation().width(400).height(150).background("green").crop("lpad")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 400, height: 150, background: "green", crop: "lpad"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 400, height: 150, background: "green", crop: "lpad"})
React:
<Image publicId="sample.jpg" >
<Transformation width="400" height="150" background="green" crop="lpad" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="400" height="150" background="green" crop="lpad" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="400" height="150" background="green" crop="lpad">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(400).Height(150).Background("green").Crop("lpad")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(400).height(150).background("green").crop("lpad")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(400).setHeight(150).setBackground("green").setCrop("lpad")).generate("sample.jpg")!, cloudinary: cloudinary)
Same as the pad
mode but only if the original image is smaller than the given minimum (width and height), in which case the image is scaled up to fill the given width and height while retaining the original aspect ratio and with all of the original image visible. This mode doesn't scale down the image if your requested dimensions are smaller than the original image's. If the proportions of the original image do not match the given width and height, padding is added to the image to reach the required size. You can also specify where the original image is placed by using the gravity parameter (set to center
by default), and specify the color of the background in the case that padding is added.
For example, attempting to minimum pad the uploaded image named sample
to a width and height of 250 pixels while retaining the aspect ratio, results in delivering the original larger image:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :crop=>"mpad")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "crop"=>"mpad"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, crop="mpad")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "mpad"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).crop("mpad")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, crop: "mpad"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "mpad"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" crop="mpad" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" crop="mpad" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" crop="mpad">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Crop("mpad")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).crop("mpad")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setCrop("mpad")).generate("sample.jpg")!, cloudinary: cloudinary)
Extract a region of the given width and height out of the original image. The original proportions are retained and so is the size of the graphics. You can specify the gravity parameter to select which part of the image to extract, or use fixed coordinates cropping.
For example, the uploaded jpg image named sample
cropped to a width of 200 pixels, a height of 150 pixels, with northwest gravity:
Ruby:
cl_image_tag("sample.jpg", :width=>200, :height=>150, :gravity=>"north_west", :crop=>"crop")
PHP:
cl_image_tag("sample.jpg", array("width"=>200, "height"=>150, "gravity"=>"north_west", "crop"=>"crop"))
Python:
CloudinaryImage("sample.jpg").image(width=200, height=150, gravity="north_west", crop="crop")
Node.js:
cloudinary.image("sample.jpg", {width: 200, height: 150, gravity: "north_west", crop: "crop"})
Java:
cloudinary.url().transformation(new Transformation().width(200).height(150).gravity("north_west").crop("crop")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 200, height: 150, gravity: "north_west", crop: "crop"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 200, height: 150, gravity: "north_west", crop: "crop"})
React:
<Image publicId="sample.jpg" >
<Transformation width="200" height="150" gravity="north_west" crop="crop" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="200" height="150" gravity="north_west" crop="crop" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="200" height="150" gravity="north_west" crop="crop">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(200).Height(150).Gravity("north_west").Crop("crop")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(200).height(150).gravity("north_west").crop("crop")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(200).setHeight(150).setGravity("north_west").setCrop("crop")).generate("sample.jpg")!, cloudinary: cloudinary)
You can specify a region of the original image to crop by giving the x
and y
coordinates of the top left corner of the region together with the width
and height
of the region. You can also use percentage based numbers instead of the exact coordinates for x
, y
, w
and h
(e.g., 0.5 for 50%) . Use this method when you know beforehand what the correct absolute cropping coordinates are, as in when your users manually select the region to crop out of the original image.
For example, the following image shows many white sheep and one brown sheep.
Ruby:
cl_image_tag("brown_sheep.jpg")
PHP:
cl_image_tag("brown_sheep.jpg")
Python:
CloudinaryImage("brown_sheep.jpg").image()
Node.js:
cloudinary.image("brown_sheep.jpg")
Java:
cloudinary.url().imageTag("brown_sheep.jpg");
JS:
cloudinary.imageTag('brown_sheep.jpg').toHtml();
jQuery:
$.cloudinary.image("brown_sheep.jpg")
React:
<Image publicId="brown_sheep.jpg" >
</Image>
Vue.js:
<cld-image publicId="brown_sheep.jpg" >
</cld-image>
Angular:
<cl-image public-id="brown_sheep.jpg" >
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.BuildImageTag("brown_sheep.jpg")
Android:
MediaManager.get().url().generate("brown_sheep.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().generate("brown_sheep.jpg")!, cloudinary: cloudinary)
To manipulate the picture so that only the brown sheep is visible, the image is cropped to a 300x200 region starting at the coordinate x = 355 and y = 410:
Ruby:
cl_image_tag("brown_sheep.jpg", :x=>355, :y=>410, :width=>300, :height=>200, :crop=>"crop")
PHP:
cl_image_tag("brown_sheep.jpg", array("x"=>355, "y"=>410, "width"=>300, "height"=>200, "crop"=>"crop"))
Python:
CloudinaryImage("brown_sheep.jpg").image(x=355, y=410, width=300, height=200, crop="crop")
Node.js:
cloudinary.image("brown_sheep.jpg", {x: 355, y: 410, width: 300, height: 200, crop: "crop"})
Java:
cloudinary.url().transformation(new Transformation().x(355).y(410).width(300).height(200).crop("crop")).imageTag("brown_sheep.jpg");
JS:
cloudinary.imageTag('brown_sheep.jpg', {x: 355, y: 410, width: 300, height: 200, crop: "crop"}).toHtml();
jQuery:
$.cloudinary.image("brown_sheep.jpg", {x: 355, y: 410, width: 300, height: 200, crop: "crop"})
React:
<Image publicId="brown_sheep.jpg" >
<Transformation x="355" y="410" width="300" height="200" crop="crop" />
</Image>
Vue.js:
<cld-image publicId="brown_sheep.jpg" >
<cld-transformation x="355" y="410" width="300" height="200" crop="crop" />
</cld-image>
Angular:
<cl-image public-id="brown_sheep.jpg" >
<cl-transformation x="355" y="410" width="300" height="200" crop="crop">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().X(355).Y(410).Width(300).Height(200).Crop("crop")).BuildImageTag("brown_sheep.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().x(355).y(410).width(300).height(200).crop("crop")).generate("brown_sheep.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setX(355).setY(410).setWidth(300).setHeight(200).setCrop("crop")).generate("brown_sheep.jpg")!, cloudinary: cloudinary)
The image can be further manipulated with chained transformations. For example, the 300x200 cropped version above, also scaled down to 150x100:
Ruby:
cl_image_tag("brown_sheep.jpg", :transformation=>[
{:x=>355, :y=>410, :width=>300, :height=>200, :crop=>"crop"},
{:width=>150, :height=>100, :crop=>"scale"}
])
PHP:
cl_image_tag("brown_sheep.jpg", array("transformation"=>array(
array("x"=>355, "y"=>410, "width"=>300, "height"=>200, "crop"=>"crop"),
array("width"=>150, "height"=>100, "crop"=>"scale")
)))
Python:
CloudinaryImage("brown_sheep.jpg").image(transformation=[
{'x': 355, 'y': 410, 'width': 300, 'height': 200, 'crop': "crop"},
{'width': 150, 'height': 100, 'crop': "scale"}
])
Node.js:
cloudinary.image("brown_sheep.jpg", {transformation: [
{x: 355, y: 410, width: 300, height: 200, crop: "crop"},
{width: 150, height: 100, crop: "scale"}
]})
Java:
cloudinary.url().transformation(new Transformation()
.x(355).y(410).width(300).height(200).crop("crop").chain()
.width(150).height(100).crop("scale")).imageTag("brown_sheep.jpg");
JS:
cloudinary.imageTag('brown_sheep.jpg', {transformation: [
{x: 355, y: 410, width: 300, height: 200, crop: "crop"},
{width: 150, height: 100, crop: "scale"}
]}).toHtml();
jQuery:
$.cloudinary.image("brown_sheep.jpg", {transformation: [
{x: 355, y: 410, width: 300, height: 200, crop: "crop"},
{width: 150, height: 100, crop: "scale"}
]})
React:
<Image publicId="brown_sheep.jpg" >
<Transformation x="355" y="410" width="300" height="200" crop="crop" />
<Transformation width="150" height="100" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="brown_sheep.jpg" >
<cld-transformation x="355" y="410" width="300" height="200" crop="crop" />
<cld-transformation width="150" height="100" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="brown_sheep.jpg" >
<cl-transformation x="355" y="410" width="300" height="200" crop="crop">
</cl-transformation>
<cl-transformation width="150" height="100" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.X(355).Y(410).Width(300).Height(200).Crop("crop").Chain()
.Width(150).Height(100).Crop("scale")).BuildImageTag("brown_sheep.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.x(355).y(410).width(300).height(200).crop("crop").chain()
.width(150).height(100).crop("scale")).generate("brown_sheep.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setX(355).setY(410).setWidth(300).setHeight(200).setCrop("crop").chain()
.setWidth(150).setHeight(100).setCrop("scale")).generate("brown_sheep.jpg")!, cloudinary: cloudinary)
Create an image with the exact given width and height without distorting the image. This option first scales up or down as much as needed to at least fill both of the given dimensions. If the requested aspect ratio is different than the original, cropping will occur on the dimension that exceeds the requested size after scaling. You can specify which part of the original image you want to keep if cropping occurs using the gravity parameter (set to center
by default).
Examples of fill used with the uploaded jpg image named sample
:
Filled to a width and height of 250 pixels:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :crop=>"fill")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "crop"=>"fill"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, crop="fill")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).crop("fill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, crop: "fill"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Crop("fill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).crop("fill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setCrop("fill")).generate("sample.jpg")!, cloudinary: cloudinary)
Filled to a width and height of 250 pixels with east gravity:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :gravity=>"east", :crop=>"fill")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "gravity"=>"east", "crop"=>"fill"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, gravity="east", crop="fill")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, gravity: "east", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).gravity("east").crop("fill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, gravity: "east", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, gravity: "east", crop: "fill"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" gravity="east" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" gravity="east" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" gravity="east" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Gravity("east").Crop("fill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).gravity("east").crop("fill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setGravity("east").setCrop("fill")).generate("sample.jpg")!, cloudinary: cloudinary)
Same as the 'fill' mode, but only if the original image is larger than the specified resolution limits, in which case the image is scaled down to fill the given width and height without distorting the image, and then the dimension that exceeds the request is cropped. If the original dimensions are smaller than the requested size, it is not resized at all. This prevents upscaling. You can specify which part of the original image you want to keep if cropping occurs using the gravity parameter (set to center
by default).
For example, the uploaded image named sample
limit filled to a width of 150 pixels and a height of 200 pixels and limiting the size to no larger than the original image:
Ruby:
cl_image_tag("sample.jpg", :width=>150, :height=>200, :crop=>"lfill")
PHP:
cl_image_tag("sample.jpg", array("width"=>150, "height"=>200, "crop"=>"lfill"))
Python:
CloudinaryImage("sample.jpg").image(width=150, height=200, crop="lfill")
Node.js:
cloudinary.image("sample.jpg", {width: 150, height: 200, crop: "lfill"})
Java:
cloudinary.url().transformation(new Transformation().width(150).height(200).crop("lfill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 150, height: 200, crop: "lfill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 150, height: 200, crop: "lfill"})
React:
<Image publicId="sample.jpg" >
<Transformation width="150" height="200" crop="lfill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="150" height="200" crop="lfill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="150" height="200" crop="lfill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(200).Crop("lfill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(150).height(200).crop("lfill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setHeight(200).setCrop("lfill")).generate("sample.jpg")!, cloudinary: cloudinary)
Tries to prevent a "bad crop" by first attempting to use the fill
mode, but adding padding if it is determined that more of the original image needs to be included in the final image. Especially useful if the aspect ratio of the delivered image is considerably different from the original's aspect ratio. Only supported in conjunction with Automatic cropping (g_auto).
For example, the uploaded jpg image named lady
delivered as a 80x400 image using the fill
mode on the left, and the fill_pad
mode on the right:
fill
fill_pad
Ruby:
cl_image_tag("lady.jpg", :width=>80, :height=>400, :gravity=>"auto", :background=>"auto", :crop=>"fill_pad")
PHP:
cl_image_tag("lady.jpg", array("width"=>80, "height"=>400, "gravity"=>"auto", "background"=>"auto", "crop"=>"fill_pad"))
Python:
CloudinaryImage("lady.jpg").image(width=80, height=400, gravity="auto", background="auto", crop="fill_pad")
Node.js:
cloudinary.image("lady.jpg", {width: 80, height: 400, gravity: "auto", background: "auto", crop: "fill_pad"})
Java:
cloudinary.url().transformation(new Transformation().width(80).height(400).gravity("auto").background("auto").crop("fill_pad")).imageTag("lady.jpg");
JS:
cloudinary.imageTag('lady.jpg', {width: 80, height: 400, gravity: "auto", background: "auto", crop: "fill_pad"}).toHtml();
jQuery:
$.cloudinary.image("lady.jpg", {width: 80, height: 400, gravity: "auto", background: "auto", crop: "fill_pad"})
React:
<Image publicId="lady.jpg" >
<Transformation width="80" height="400" gravity="auto" background="auto" crop="fill_pad" />
</Image>
Vue.js:
<cld-image publicId="lady.jpg" >
<cld-transformation width="80" height="400" gravity="auto" background="auto" crop="fill_pad" />
</cld-image>
Angular:
<cl-image public-id="lady.jpg" >
<cl-transformation width="80" height="400" gravity="auto" background="auto" crop="fill_pad">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(80).Height(400).Gravity("auto").Background("auto").Crop("fill_pad")).BuildImageTag("lady.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(80).height(400).gravity("auto").background("auto").crop("fill_pad")).generate("lady.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(80).setHeight(400).setGravity("auto").setBackground("auto").setCrop("fill_pad")).generate("lady.jpg")!, cloudinary: cloudinary)
The thumb
cropping mode is specifically used for creating image thumbnails from either face or custom coordinates, and must always be accompanied by the gravity parameter set to one of the face detection or custom values. This cropping mode generates a thumbnail of an image with the exact given width and height dimensions and with the original proportions retained, but the resulting image might be scaled to fit in the given dimensions. You can specify the zoom parameter to determine how much to scale the resulting image within the given width and height.
For example, creating a 150x150 thumbnail with face detection, of the uploaded image called woman
. Below you can see the original image as well as the face detection based thumbnail:
Ruby:
cl_image_tag("woman.jpg", :gravity=>"face", :width=>150, :height=>150, :crop=>"thumb")
PHP:
cl_image_tag("woman.jpg", array("gravity"=>"face", "width"=>150, "height"=>150, "crop"=>"thumb"))
Python:
CloudinaryImage("woman.jpg").image(gravity="face", width=150, height=150, crop="thumb")
Node.js:
cloudinary.image("woman.jpg", {gravity: "face", width: 150, height: 150, crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().gravity("face").width(150).height(150).crop("thumb")).imageTag("woman.jpg");
JS:
cloudinary.imageTag('woman.jpg', {gravity: "face", width: 150, height: 150, crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("woman.jpg", {gravity: "face", width: 150, height: 150, crop: "thumb"})
React:
<Image publicId="woman.jpg" >
<Transformation gravity="face" width="150" height="150" crop="thumb" />
</Image>
Vue.js:
<cld-image publicId="woman.jpg" >
<cld-transformation gravity="face" width="150" height="150" crop="thumb" />
</cld-image>
Angular:
<cl-image public-id="woman.jpg" >
<cl-transformation gravity="face" width="150" height="150" crop="thumb">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Gravity("face").Width(150).Height(150).Crop("thumb")).BuildImageTag("woman.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().gravity("face").width(150).height(150).crop("thumb")).generate("woman.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setGravity("face").setWidth(150).setHeight(150).setCrop("thumb")).generate("woman.jpg")!, cloudinary: cloudinary)
Use the aspect_ratio
parameter (ar
in URLs) to resize or crop the image to a new aspect ratio. This parameter can be used together with a specified crop mode to adjust the delivered asset to the required dimensions. This parameter can also be used in conjunction with either the width
or height
parameters (w
and h
in URLs) - the other dimension is then automatically calculated to deliver the asset in the requested aspect ratio.
The aspect_ratio
parameter accepts a value in one of the following forms:
a:b
where a
signifies the relative width and b
the relative height (e.g., 4:3 or 16:9).
- a decimal value representing the ratio of the width divided by the height (e.g., 1.33 or 2.5).
Examples with the uploaded image named sample
:
- Cropped to an aspect ratio of 2.5:
Ruby:
cl_image_tag("sample.jpg", :aspect_ratio=>"2.5", :crop=>"crop")
PHP:
cl_image_tag("sample.jpg", array("aspect_ratio"=>"2.5", "crop"=>"crop"))
Python:
CloudinaryImage("sample.jpg").image(aspect_ratio="2.5", crop="crop")
Node.js:
cloudinary.image("sample.jpg", {aspect_ratio: "2.5", crop: "crop"})
Java:
cloudinary.url().transformation(new Transformation().aspectRatio("2.5").crop("crop")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {aspectRatio: "2.5", crop: "crop"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {aspect_ratio: "2.5", crop: "crop"})
React:
<Image publicId="sample.jpg" >
<Transformation aspectRatio="2.5" crop="crop" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation aspectRatio="2.5" crop="crop" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation aspect-ratio="2.5" crop="crop">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().AspectRatio("2.5").Crop("crop")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().aspectRatio("2.5").crop("crop")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setAspectRatio("2.5").setCrop("crop")).generate("sample.jpg")!, cloudinary: cloudinary)
- Filled to an aspect ratio of 16:9:
Ruby:
cl_image_tag("sample.jpg", :aspect_ratio=>"16:9", :crop=>"fill")
PHP:
cl_image_tag("sample.jpg", array("aspect_ratio"=>"16:9", "crop"=>"fill"))
Python:
CloudinaryImage("sample.jpg").image(aspect_ratio="16:9", crop="fill")
Node.js:
cloudinary.image("sample.jpg", {aspect_ratio: "16:9", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().aspectRatio("16:9").crop("fill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {aspectRatio: "16:9", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {aspect_ratio: "16:9", crop: "fill"})
React:
<Image publicId="sample.jpg" >
<Transformation aspectRatio="16:9" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation aspectRatio="16:9" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation aspect-ratio="16:9" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().AspectRatio("16:9").Crop("fill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().aspectRatio("16:9").crop("fill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setAspectRatio("16:9").setCrop("fill")).generate("sample.jpg")!, cloudinary: cloudinary)
- Filled to a width of 400 pixels with an aspect ratio of 4:3:
Ruby:
cl_image_tag("sample.jpg", :width=>400, :aspect_ratio=>"4:3", :crop=>"fill")
PHP:
cl_image_tag("sample.jpg", array("width"=>400, "aspect_ratio"=>"4:3", "crop"=>"fill"))
Python:
CloudinaryImage("sample.jpg").image(width=400, aspect_ratio="4:3", crop="fill")
Node.js:
cloudinary.image("sample.jpg", {width: 400, aspect_ratio: "4:3", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(400).aspectRatio("4:3").crop("fill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 400, aspectRatio: "4:3", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 400, aspect_ratio: "4:3", crop: "fill"})
React:
<Image publicId="sample.jpg" >
<Transformation width="400" aspectRatio="4:3" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="400" aspectRatio="4:3" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="400" aspect-ratio="4:3" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(400).AspectRatio("4:3").Crop("fill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(400).aspectRatio("4:3").crop("fill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(400).setAspectRatio("4:3").setCrop("fill")).generate("sample.jpg")!, cloudinary: cloudinary)
Different devices support different DPR values, which is defined as the ratio between physical pixels and logical pixels. This means that a device with support for a higher DPR uses more physical pixels for displaying an image, resulting in a clearer, sharper image.
Use the dpr
parameter to set the DPR value of the delivered image. The parameter accepts a numeric value specifying the DPR multiplier.
The dpr
parameter is especially useful when adding overlays, as you need the overlay image to be correctly resized according to the required pixel density of the device (along with the containing image). Setting the dpr transformation parameter applies the same resizing rules both to the containing image, and the included overlay.
For example, the following URL dynamically generates a 100x100 face-detection-based circular thumbnail of an image named lady
, and adds another image named cloudinary_icon_white
as a semi-transparent watermark with a width of 50 pixels. Setting the dpr value to 1.0, 2.0 (as in the code example) or 3.0 generates the following images, while resizing both the containing image and the overlay to match the required DPR.
Ruby:
cl_image_tag("lady.jpg", :transformation=>[
{:width=>100, :height=>100, :gravity=>"face", :radius=>"max", :crop=>"thumb"},
{:overlay=>"cloudinary_icon_white", :effect=>"brightness:200", :flags=>"relative", :width=>0.5, :opacity=>60},
{:dpr=>2.0}
])
PHP:
cl_image_tag("lady.jpg", array("transformation"=>array(
array("width"=>100, "height"=>100, "gravity"=>"face", "radius"=>"max", "crop"=>"thumb"),
array("overlay"=>"cloudinary_icon_white", "effect"=>"brightness:200", "flags"=>"relative", "width"=>"0.5", "opacity"=>60),
array("dpr"=>"2.0")
)))
Python:
CloudinaryImage("lady.jpg").image(transformation=[
{'width': 100, 'height': 100, 'gravity': "face", 'radius': "max", 'crop': "thumb"},
{'overlay': "cloudinary_icon_white", 'effect': "brightness:200", 'flags': "relative", 'width': "0.5", 'opacity': 60},
{'dpr': "2.0"}
])
Node.js:
cloudinary.image("lady.jpg", {transformation: [
{width: 100, height: 100, gravity: "face", radius: "max", crop: "thumb"},
{overlay: "cloudinary_icon_white", effect: "brightness:200", flags: "relative", width: "0.5", opacity: 60},
{dpr: "2.0"}
]})
Java:
cloudinary.url().transformation(new Transformation()
.width(100).height(100).gravity("face").radius("max").crop("thumb").chain()
.overlay(new Layer().publicId("cloudinary_icon_white")).effect("brightness:200").flags("relative").width(0.5).opacity(60).chain()
.dpr(2.0)).imageTag("lady.jpg");
JS:
cloudinary.imageTag('lady.jpg', {transformation: [
{width: 100, height: 100, gravity: "face", radius: "max", crop: "thumb"},
{overlay: new cloudinary.Layer().publicId("cloudinary_icon_white"), effect: "brightness:200", flags: "relative", width: "0.5", opacity: 60},
{dpr: "2.0"}
]}).toHtml();
jQuery:
$.cloudinary.image("lady.jpg", {transformation: [
{width: 100, height: 100, gravity: "face", radius: "max", crop: "thumb"},
{overlay: new cloudinary.Layer().publicId("cloudinary_icon_white"), effect: "brightness:200", flags: "relative", width: "0.5", opacity: 60},
{dpr: "2.0"}
]})
React:
<Image publicId="lady.jpg" >
<Transformation width="100" height="100" gravity="face" radius="max" crop="thumb" />
<Transformation overlay="cloudinary_icon_white" effect="brightness:200" flags="relative" width="0.5" opacity="60" />
<Transformation dpr="2.0" />
</Image>
Vue.js:
<cld-image publicId="lady.jpg" >
<cld-transformation width="100" height="100" gravity="face" radius="max" crop="thumb" />
<cld-transformation overlay="cloudinary_icon_white" effect="brightness:200" flags="relative" width="0.5" opacity="60" />
<cld-transformation dpr="2.0" />
</cld-image>
Angular:
<cl-image public-id="lady.jpg" >
<cl-transformation width="100" height="100" gravity="face" radius="max" crop="thumb">
</cl-transformation>
<cl-transformation overlay="cloudinary_icon_white" effect="brightness:200" flags="relative" width="0.5" opacity="60">
</cl-transformation>
<cl-transformation dpr="2.0">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(100).Height(100).Gravity("face").Radius("max").Crop("thumb").Chain()
.Overlay(new Layer().PublicId("cloudinary_icon_white")).Effect("brightness:200").Flags("relative").Width(0.5).Opacity(60).Chain()
.Dpr(2.0)).BuildImageTag("lady.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.width(100).height(100).gravity("face").radius("max").crop("thumb").chain()
.overlay(new Layer().publicId("cloudinary_icon_white")).effect("brightness:200").flags("relative").width(0.5).opacity(60).chain()
.dpr(2.0)).generate("lady.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setWidth(100).setHeight(100).setGravity("face").setRadius("max").setCrop("thumb").chain()
.setOverlay("cloudinary_icon_white").setEffect("brightness:200").setFlags("relative").setWidth(0.5).setOpacity(60).chain()
.setDpr(2.0)).generate("lady.jpg")!, cloudinary: cloudinary)



DPR 1.0 DPR 2.0 DPR 3.0
Now you can create a 100x100 HTML image tag and deliver an image with the resolution that best matches the specified pixel density of your users' devices. The three images below are all displayed within a 100x100 logical square using the <img>
tag width and height attributes, while you see more details and a better visual result for the last two images if you view this documentation using a device that supports a higher DPR.
<img
src="https://res.cloudinary.com/demo/image/upload/c_thumb,w_100,h_100,g_face,r_max/l_cloudinary_icon_white,e_brightness:200,w_50,o_60/dpr_2.0/lady.jpg"
height=100
width=100 />



DPR 1.0 (100x100, 4.1KB) DPR 2.0 (200x200, 10.1KB) DPR 3.0 (300x300, 22.3KB)
You can alternatively use dpr_auto
to automatically deliver the best image, depending on the requesting device's support for DPR. For details, see the Responsive images documentation.
The gravity
parameter (g
in URLs) is used to specify a location in the image that is used as the focus for another transformation:
- For certain cropping modes, gravity specifies which part of the original image to include when the resulting image is smaller than the original or the proportions do not match.
- For placing underlays, overlays or text captions, gravity specifies where to place them in relation to the original image.
The basic gravity value is specified by giving a compass direction to include: north_east
, north
, north_west
, west
, south_west
, south
, south_east
, east
, or center
(the default value). The compass direction represents a location in the image, for example, north_east
represents the top right corner.
For example, the uploaded jpg image named sample
filled to a width and height of 250 pixels while retaining the aspect ratio:
- Original image:
Ruby:
cl_image_tag("sample.jpg")
PHP:
cl_image_tag("sample.jpg")
Python:
CloudinaryImage("sample.jpg").image()
Node.js:
cloudinary.image("sample.jpg")
Java:
cloudinary.url().imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg').toHtml();
jQuery:
$.cloudinary.image("sample.jpg")
React:
<Image publicId="sample.jpg" >
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().generate("sample.jpg")!, cloudinary: cloudinary)
- With gravity set to north:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :gravity=>"north", :crop=>"fill")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "gravity"=>"north", "crop"=>"fill"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, gravity="north", crop="fill")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, gravity: "north", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).gravity("north").crop("fill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, gravity: "north", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, gravity: "north", crop: "fill"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" gravity="north" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" gravity="north" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" gravity="north" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Gravity("north").Crop("fill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).gravity("north").crop("fill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setGravity("north").setCrop("fill")).generate("sample.jpg")!, cloudinary: cloudinary)
- With gravity set to south_east:
Ruby:
cl_image_tag("sample.jpg", :width=>250, :height=>250, :gravity=>"south_east", :crop=>"fill")
PHP:
cl_image_tag("sample.jpg", array("width"=>250, "height"=>250, "gravity"=>"south_east", "crop"=>"fill"))
Python:
CloudinaryImage("sample.jpg").image(width=250, height=250, gravity="south_east", crop="fill")
Node.js:
cloudinary.image("sample.jpg", {width: 250, height: 250, gravity: "south_east", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(250).gravity("south_east").crop("fill")).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {width: 250, height: 250, gravity: "south_east", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {width: 250, height: 250, gravity: "south_east", crop: "fill"})
React:
<Image publicId="sample.jpg" >
<Transformation width="250" height="250" gravity="south_east" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="250" height="250" gravity="south_east" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="250" height="250" gravity="south_east" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(250).Gravity("south_east").Crop("fill")).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(250).gravity("south_east").crop("fill")).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(250).setGravity("south_east").setCrop("fill")).generate("sample.jpg")!, cloudinary: cloudinary)
There are also a number of special positions available to use as the focal point for gravity, for example g_face
to automatically detect the largest face in an image and make it the focus of the transformation, and g_custom
to use custom coordinates that were previously specified (e.g., as part of the image upload method) and make them the focus of the transformation.
For a full listing of the available gravity positions, see special positions in the transformation reference guide.
Setting the gravity
transformation parameter to liquid
(g_liquid
in URLs), enables content-aware liquid rescaling (also sometimes known as 'seam carving'), which can be useful when changing the aspect ratio of an image. Normal scaling retains all image content even when aspect ratios change, so important elements of an image can be distorted. Liquid rescaling intelligently removes or duplicates 'seams' of pixels that may zig zag horizontally or vertically through the picture. The seams are determined using an algorithm that selects pixels with the least importance (least color change on either side of the seam). The result is an image where the most 'important' elements of the image are retained and generally do not appear distorted although the relative height or width of items in an image may change, especially if you significantly change the aspect ratio.
Tips and guidelines for liquid gravity:
- It can be used only in conjunction with c_scale.
- The
liquid
gravity works best when applied to scenic images with large 'unbusy' sections such as sky, grass, or water.
- It also works best when applied to larger images. Thus, it is recommended to use this gravity to change aspect ratio using relative widths and heights, where one of the two dimensions remains at or close to
1.0
. If you also want to resize the image, apply the resize on a different component of a chained transformation.
- In some cases, over-aggressive liquid rescaling can result in significant artifacts.
For example, using liquid scaling to change an image to a square (aspect ratio of 1:1) based on the original image width, and then resize the result to 500x500:
Ruby:
cl_image_tag("country_sunset.jpg", :transformation=>[
{:aspect_ratio=>"1.0", :gravity=>"liquid", :width=>1.0, :crop=>"scale"},
{:width=>500, :height=>500, :crop=>"scale"}
])
PHP:
cl_image_tag("country_sunset.jpg", array("transformation"=>array(
array("aspect_ratio"=>"1.0", "gravity"=>"liquid", "width"=>"1.0", "crop"=>"scale"),
array("width"=>500, "height"=>500, "crop"=>"scale")
)))
Python:
CloudinaryImage("country_sunset.jpg").image(transformation=[
{'aspect_ratio': "1.0", 'gravity': "liquid", 'width': "1.0", 'crop': "scale"},
{'width': 500, 'height': 500, 'crop': "scale"}
])
Node.js:
cloudinary.image("country_sunset.jpg", {transformation: [
{aspect_ratio: "1.0", gravity: "liquid", width: "1.0", crop: "scale"},
{width: 500, height: 500, crop: "scale"}
]})
Java:
cloudinary.url().transformation(new Transformation()
.aspectRatio("1.0").gravity("liquid").width(1.0).crop("scale").chain()
.width(500).height(500).crop("scale")).imageTag("country_sunset.jpg");
JS:
cloudinary.imageTag('country_sunset.jpg', {transformation: [
{aspectRatio: "1.0", gravity: "liquid", width: "1.0", crop: "scale"},
{width: 500, height: 500, crop: "scale"}
]}).toHtml();
jQuery:
$.cloudinary.image("country_sunset.jpg", {transformation: [
{aspect_ratio: "1.0", gravity: "liquid", width: "1.0", crop: "scale"},
{width: 500, height: 500, crop: "scale"}
]})
React:
<Image publicId="country_sunset.jpg" >
<Transformation aspectRatio="1.0" gravity="liquid" width="1.0" crop="scale" />
<Transformation width="500" height="500" crop="scale" />
</Image>
Vue.js:
<cld-image publicId="country_sunset.jpg" >
<cld-transformation aspectRatio="1.0" gravity="liquid" width="1.0" crop="scale" />
<cld-transformation width="500" height="500" crop="scale" />
</cld-image>
Angular:
<cl-image public-id="country_sunset.jpg" >
<cl-transformation aspect-ratio="1.0" gravity="liquid" width="1.0" crop="scale">
</cl-transformation>
<cl-transformation width="500" height="500" crop="scale">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.AspectRatio("1.0").Gravity("liquid").Width(1.0).Crop("scale").Chain()
.Width(500).Height(500).Crop("scale")).BuildImageTag("country_sunset.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.aspectRatio("1.0").gravity("liquid").width(1.0).crop("scale").chain()
.width(500).height(500).crop("scale")).generate("country_sunset.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setAspectRatio("1.0").setGravity("liquid").setWidth(1.0).setCrop("scale").chain()
.setWidth(500).setHeight(500).setCrop("scale")).generate("country_sunset.jpg")!, cloudinary: cloudinary)
Cloudinary's intelligent gravity selection capabilities ensure that the most interesting areas of each image are selected as the main focus for the requested crop, not only for photos with faces, but for any content type. Each image is analyzed individually to find the optimal region to include while cropping, and automatically detected faces (or other elements) are given higher priority while analyzing the image content (although any custom coordinates defined will override the detection algorithm).
You apply automatic content-aware gravity by setting the gravity
transformation parameter to auto
(g_auto
in URLs).
Automatic cropping is supported for the fill, lfill, fill_pad, thumb and crop modes.
- If custom coordinates have been specified for an image (using the Upload API or the Management Console), the cropping or overlay will be based on that definition, taking the custom coordinates as-is and overriding the detection algorithm (the same as
g_custom
). This applies to all focal_gravity
options except for g_auto:custom_no_override
and g_auto:none
.
- You can add the getinfo flag (
fl_getinfo
in URLs) in your transformation to return the proposed g_auto
cropping results in JSON instead of delivering the transformed image. You can then integrate the g_auto
results into an external workflow, for example to display the proposed g_auto
crop as the initial cropping suggestion in an external editing tool.
- By default,
g_auto
applies an optimal combination of our AI and saliency-based algorithms to capture the best region to include in your cropped image. However, in certain situations you may want to explicitly request only one of the auto-cropping algorithms and/or adjust the default focal preference of the chosen algorithm.
The default g_auto
option applies an optimal mixture of two different methods of identifying the most important region of your image:
- AI-based algorithm (subject) - Uses deep-learning algorithms to identify the subjects of an image that are most likely to attract a person's gaze.
- Saliency algorithm (classic) - Uses a combination of saliency heuristics, edge detection, light, skin-tone prioritization, and more to automatically detect and prioritize significant region(s) in the image.
In the majority of cases, the most salient elements in an image are also the main subjects of the photo, and thus both algorithms often produce very similar or identical results. However, in some cases, results can be somewhat different and therefore the weighted mixture that g_auto
applies by default usually gives the best results.
But if you find that for the types of images you are delivering, one of the algorithms consistently gives a better result than the other, you can override the default combined mechanism and instead explicitly request your preferred algorithm by specifying auto:subject
or auto:classic
as the gravity value (g_auto:subject
or g_auto:classic
in URLs), with or without an additional focal gravity option.
For example, when cropping the landscape image below to a portrait view, the classic algorithm selects the areas with the most graphically salient spots, which include the tree against the bright blue and white sky, while the subject algorithm focuses on the subjects that the AI-engine predicts are most likely to capture human attention, primarily the boat, lake and mountains.
Original image
Default crop
(Center gravity)
Auto-gravity
Saliency (classic) method
Auto-gravity
AI-based subject method
By default, both the saliency and subject auto-cropping algorithms give increased priority to detected faces
. To adjust the focal preference of the automatic cropping algorithm, you can specify a different focal_gravity
option.
For example, you can specify adv_face
, adv_faces
, or adv_eyes
to instruct the algorithm to give priority to the eyes or faces detected by the Advanced Facial Attributes Detection add-on (as opposed to the coordinates selected by the built-in face-detection mechanism). Alternatively, you can use the value none
if you don't want the algorithm to give special preference to any detected item, including faces.
If you are registered to the Cloudinary Object-Aware Cropping Add-on, you can also instruct the gravity algorithm to give top priority to one or more specific objects or categories from an extensive list.
Additionally, the OCR Text Detection and Extraction Add-on lets you give a higher priority to text by setting the gravity
parameter to auto:ocr_text
, while also giving priority to faces and other very prominent elements of an image.
For a complete list of all focal_gravity
options, see the g_<special_position> section of the Transformation URL API Reference.
Keeping the most of the original image according to the requested dimensions of the derived image. Ensuring that as much as possible of the most interesting regions of the original image is included in the resulting image.
Example of portrait aspect ratio cropping, regular vs. automatic:
Original
w_200,h_300,c_fill,g_centerRegular fill
w_200,h_300,c_fill,g_autoAutomatic fill
Ruby:
cl_image_tag("basketball_in_net.jpg", :width=>200, :height=>300, :gravity=>"auto", :crop=>"fill")
PHP:
cl_image_tag("basketball_in_net.jpg", array("width"=>200, "height"=>300, "gravity"=>"auto", "crop"=>"fill"))
Python:
CloudinaryImage("basketball_in_net.jpg").image(width=200, height=300, gravity="auto", crop="fill")
Node.js:
cloudinary.image("basketball_in_net.jpg", {width: 200, height: 300, gravity: "auto", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(200).height(300).gravity("auto").crop("fill")).imageTag("basketball_in_net.jpg");
JS:
cloudinary.imageTag('basketball_in_net.jpg', {width: 200, height: 300, gravity: "auto", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("basketball_in_net.jpg", {width: 200, height: 300, gravity: "auto", crop: "fill"})
React:
<Image publicId="basketball_in_net.jpg" >
<Transformation width="200" height="300" gravity="auto" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="basketball_in_net.jpg" >
<cld-transformation width="200" height="300" gravity="auto" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="basketball_in_net.jpg" >
<cl-transformation width="200" height="300" gravity="auto" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(200).Height(300).Gravity("auto").Crop("fill")).BuildImageTag("basketball_in_net.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(200).height(300).gravity("auto").crop("fill")).generate("basketball_in_net.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(200).setHeight(300).setGravity("auto").setCrop("fill")).generate("basketball_in_net.jpg")!, cloudinary: cloudinary)
Example of square aspect ratio cropping, regular vs. automatic:
Original
w_200,h_200,c_fill,g_centerRegular fill
w_200,h_200,c_fill,g_autoAutomatic fill
Ruby:
cl_image_tag("face_left.jpg", :width=>200, :height=>200, :gravity=>"auto", :crop=>"fill")
PHP:
cl_image_tag("face_left.jpg", array("width"=>200, "height"=>200, "gravity"=>"auto", "crop"=>"fill"))
Python:
CloudinaryImage("face_left.jpg").image(width=200, height=200, gravity="auto", crop="fill")
Node.js:
cloudinary.image("face_left.jpg", {width: 200, height: 200, gravity: "auto", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(200).height(200).gravity("auto").crop("fill")).imageTag("face_left.jpg");
JS:
cloudinary.imageTag('face_left.jpg', {width: 200, height: 200, gravity: "auto", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("face_left.jpg", {width: 200, height: 200, gravity: "auto", crop: "fill"})
React:
<Image publicId="face_left.jpg" >
<Transformation width="200" height="200" gravity="auto" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="face_left.jpg" >
<cld-transformation width="200" height="200" gravity="auto" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="face_left.jpg" >
<cl-transformation width="200" height="200" gravity="auto" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(200).Height(200).Gravity("auto").Crop("fill")).BuildImageTag("face_left.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(200).height(200).gravity("auto").crop("fill")).generate("face_left.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(200).setHeight(200).setGravity("auto").setCrop("fill")).generate("face_left.jpg")!, cloudinary: cloudinary)
Same as the fill mode, but only if the original image is larger than the given limit (width and height). This mode doesn't scale up the image if your requested dimensions are bigger than the original image's.
Makes possible more aggressive cropping than the fill mode. This mode attempts to further zoom in and crop out less interesting image regions when relevant in order to include the most interesting objects in the resulting derived image. The automatic cropping algorithm decides whether and how aggressively to zoom-in and crop according to the content and cropping ratio of each image individually. A numerical value between 0 and 100 can be added to the g_auto
parameter in order to advise the algorithm regarding the desired aggressiveness level (e.g., g_auto:0
for the most aggressive thumb cropping).
Example of a square thumbnail, regular vs. automatic cropping:
Original
c_thumb,g_center Regular thumbnail
c_thumb,g_auto Automatic thumbnail
c_thumb,g_auto:0 Automatic thumbnail - most aggressive
Ruby:
cl_image_tag("sunset_shoes.jpg", :width=>150, :height=>150, :gravity=>"auto:0", :crop=>"thumb")
PHP:
cl_image_tag("sunset_shoes.jpg", array("width"=>150, "height"=>150, "gravity"=>"auto:0", "crop"=>"thumb"))
Python:
CloudinaryImage("sunset_shoes.jpg").image(width=150, height=150, gravity="auto:0", crop="thumb")
Node.js:
cloudinary.image("sunset_shoes.jpg", {width: 150, height: 150, gravity: "auto:0", crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().width(150).height(150).gravity("auto:0").crop("thumb")).imageTag("sunset_shoes.jpg");
JS:
cloudinary.imageTag('sunset_shoes.jpg', {width: 150, height: 150, gravity: "auto:0", crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("sunset_shoes.jpg", {width: 150, height: 150, gravity: "auto:0", crop: "thumb"})
React:
<Image publicId="sunset_shoes.jpg" >
<Transformation width="150" height="150" gravity="auto:0" crop="thumb" />
</Image>
Vue.js:
<cld-image publicId="sunset_shoes.jpg" >
<cld-transformation width="150" height="150" gravity="auto:0" crop="thumb" />
</cld-image>
Angular:
<cl-image public-id="sunset_shoes.jpg" >
<cl-transformation width="150" height="150" gravity="auto:0" crop="thumb">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(150).Gravity("auto:0").Crop("thumb")).BuildImageTag("sunset_shoes.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(150).height(150).gravity("auto:0").crop("thumb")).generate("sunset_shoes.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setHeight(150).setGravity("auto:0").setCrop("thumb")).generate("sunset_shoes.jpg")!, cloudinary: cloudinary)
The numeric value supplied for
auto
gravity together with
thumb
cropping indicates your preference for more or less aggressive zooming and the algorithm takes that preference into account. However, the automatic gravity algorithm may still determine that for a particular image and aspect ratio, its default zoom selection is the appropriate zoom for this image. In such a case, you may not see a difference between the default
g_auto
and
g_auto
with a specific agressiveness level.
Crop a region of exactly the given width and height out of the original image while automatically focusing on the most interesting region of the original image that fits within the required dimensions. The portion of the interesting area depends on the resolution of the original image. The crop
mode is less useful than the fill, lfill, and thumb modes, as it is only practical to use when both the dimensions of the original image and the size of the interesting region are already known.
Example of a square crop, regular vs. auto cropping:
Original
c_crop,g_center Regular crop
c_crop,g_auto Automatic crop
Ruby:
cl_image_tag("fat_cat.jpg", :width=>200, :height=>200, :gravity=>"auto", :crop=>"crop")
PHP:
cl_image_tag("fat_cat.jpg", array("width"=>200, "height"=>200, "gravity"=>"auto", "crop"=>"crop"))
Python:
CloudinaryImage("fat_cat.jpg").image(width=200, height=200, gravity="auto", crop="crop")
Node.js:
cloudinary.image("fat_cat.jpg", {width: 200, height: 200, gravity: "auto", crop: "crop"})
Java:
cloudinary.url().transformation(new Transformation().width(200).height(200).gravity("auto").crop("crop")).imageTag("fat_cat.jpg");
JS:
cloudinary.imageTag('fat_cat.jpg', {width: 200, height: 200, gravity: "auto", crop: "crop"}).toHtml();
jQuery:
$.cloudinary.image("fat_cat.jpg", {width: 200, height: 200, gravity: "auto", crop: "crop"})
React:
<Image publicId="fat_cat.jpg" >
<Transformation width="200" height="200" gravity="auto" crop="crop" />
</Image>
Vue.js:
<cld-image publicId="fat_cat.jpg" >
<cld-transformation width="200" height="200" gravity="auto" crop="crop" />
</cld-image>
Angular:
<cl-image public-id="fat_cat.jpg" >
<cl-transformation width="200" height="200" gravity="auto" crop="crop">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(200).Height(200).Gravity("auto").Crop("crop")).BuildImageTag("fat_cat.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().width(200).height(200).gravity("auto").crop("crop")).generate("fat_cat.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(200).setHeight(200).setGravity("auto").setCrop("crop")).generate("fat_cat.jpg")!, cloudinary: cloudinary)
Control the visual quality and compression level of JPEG, JPEG 2000, JPEG XR, WebP and GIF images with the quality
parameter (q
in URLs). This parameter represents the compression level to apply to an image as a value between 1 (smallest file size possible) and 100 (best visual quality). Reducing the quality is a trade-off between visual quality and file size: the lower the quality value, the more the file is compressed to a smaller file size, the more data is lost in the process, and the result is a loss of visual quality. The loss of visual quality is barely noticeable to the human eye at the higher quality levels, and final visual quality also depends on other factors such as the size of the image and the resolution of the user's monitor or mobile screen.
For example, reducing the quality of the uploaded JPEG image named sample
to 60 results in a file size of 73 KB compared to the original file size of 245 KB with a barely noticeable reduction in visual quality:
Ruby:
cl_image_tag("sample.jpg", :quality=>60)
PHP:
cl_image_tag("sample.jpg", array("quality"=>60))
Python:
CloudinaryImage("sample.jpg").image(quality=60)
Node.js:
cloudinary.image("sample.jpg", {quality: 60})
Java:
cloudinary.url().transformation(new Transformation().quality(60)).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {quality: 60}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {quality: 60})
React:
<Image publicId="sample.jpg" >
<Transformation quality="60" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation quality="60" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation quality="60">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality(60)).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().quality(60)).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality(60)).generate("sample.jpg")!, cloudinary: cloudinary)
The quality parameter is also automatically applied when delivering images with any other transformation applied. That is, unless the original uploaded image is requested, then a default quality value of 80 is also automatically applied to the transformed image.
The interactive image example below shows the effect that the various quality settings have on an image's visual quality. The image is scaled down to a width of 600 pixels and initially displayed with a quality setting of 100. Click on the quality buttons below the image to see how different quality settings impact the image quality.
Quality:
100
Size:
228KB
10
20
30
40
50
60
70
80
90
100
- Images in the WebP format are lossless when specifying a quality of 100, and lossy when specifying a quality less than 100. See the How to support WebP images, save bandwidth and improve user experience article for more information on the WebP format.
- Images in the WebP format are lossless if the quality isn't specified and the original image's format is lossless (e.g., PNG).
- Animated GIFs ignore the quality setting unless the
lossy
flag is added. See the Lossy compression for optimizing animated GIFs article for more information.
- The JPEGmini add-on automatically applies the best compression possible to JPEG images while maintaining a high visual quality.
Cloudinary's intelligent quality and encoding algorithm analyzes an image to find the best quality compression level and optimal encoding settings based on the image content and the viewing browser, in order to produce an image with good visual quality while minimizing the file size. Cloudinary automates the file size versus quality trade-off decision, on the fly, by using perceptual metrics and heuristics that tune the quality settings based on the specific image content and format. Analyzing every image individually to find the optimal compression level and image encoding settings allows for precise adjustment of the compression level complemented by fine tuning of the encoding settings, and can significantly reduce the file size without any degradation noticeable to the human eye.
The quality
transformation parameter can be set to auto
(q_auto
in URLs) in order to perform automatic quality selection and image encoding adjustments. Further control of the automatic quality selection is supported as follows:
q_auto
- The optimal balance between file size and visual quality. By default, this is the same as q_auto:good
, while it can automatically switch to the more aggressive q_auto:eco
mode (see the note on Save-data support below).
q_auto:best
- Less aggressive algorithm. Generates bigger files with potentially better visual quality. Example of a target audience: photography sites that display images with a high visual quality.
q_auto:good
- Ensuring a relatively small file size with good visual quality.
q_auto:eco
- More aggressive algorithm, which results in smaller files of slightly lower visual quality. Example of a target audience: popular sites and social networks with a huge amount of traffic.
q_auto:low
- Most aggressive algorithm, which results in the smallest files of low visual quality. Example of a target audience: sites using thumbnail images that link to higher quality images.
Examples of the resulting file size when encoding a photograph, using various regular and automatic quality parameter values:
Original (569KB)
q_80 (80.3KB)
q_auto:best (65.9KB)
q_auto:good (56.9KB)
q_auto:eco (45.0KB)
q_auto:low (35.0KB)
Ruby:
cl_image_tag("woman.jpg", :quality=>"auto")
PHP:
cl_image_tag("woman.jpg", array("quality"=>"auto"))
Python:
CloudinaryImage("woman.jpg").image(quality="auto")
Node.js:
cloudinary.image("woman.jpg", {quality: "auto"})
Java:
cloudinary.url().transformation(new Transformation().quality("auto")).imageTag("woman.jpg");
JS:
cloudinary.imageTag('woman.jpg', {quality: "auto"}).toHtml();
jQuery:
$.cloudinary.image("woman.jpg", {quality: "auto"})
React:
<Image publicId="woman.jpg" >
<Transformation quality="auto" />
</Image>
Vue.js:
<cld-image publicId="woman.jpg" >
<cld-transformation quality="auto" />
</cld-image>
Angular:
<cl-image public-id="woman.jpg" >
<cl-transformation quality="auto">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality("auto")).BuildImageTag("woman.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().quality("auto")).generate("woman.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality("auto")).generate("woman.jpg")!, cloudinary: cloudinary)
Examples of the resulting file size when encoding a drawing, using regular and automatic quality values:
Original (296KB)
q_80 (223KB)
q_auto:best (226KB)
q_auto:good (156KB)
q_auto:eco (97.5KB)
q_auto:low (87.5KB)
Ruby:
cl_image_tag("robot.jpg", :quality=>"auto")
PHP:
cl_image_tag("robot.jpg", array("quality"=>"auto"))
Python:
CloudinaryImage("robot.jpg").image(quality="auto")
Node.js:
cloudinary.image("robot.jpg", {quality: "auto"})
Java:
cloudinary.url().transformation(new Transformation().quality("auto")).imageTag("robot.jpg");
JS:
cloudinary.imageTag('robot.jpg', {quality: "auto"}).toHtml();
jQuery:
$.cloudinary.image("robot.jpg", {quality: "auto"})
React:
<Image publicId="robot.jpg" >
<Transformation quality="auto" />
</Image>
Vue.js:
<cld-image publicId="robot.jpg" >
<cld-transformation quality="auto" />
</cld-image>
Angular:
<cl-image public-id="robot.jpg" >
<cl-transformation quality="auto">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality("auto")).BuildImageTag("robot.jpg")
Android:
MediaManager.get().url().transformation(new Transformation().quality("auto")).generate("robot.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality("auto")).generate("robot.jpg")!, cloudinary: cloudinary)
The interactive image example below shows the effect that the various auto
quality settings have on the visual quality of the beach image. The image is initially displayed with a quality setting of 100, and clicking on one of the buttons below the image will display the image using that particular quality setting.
Quality:
100
Size:
228KB
auto:low
auto:eco
auto:good
auto:best
80
100
q_auto
cannot be used within named transformations, however q_auto:[Mode]
(e.g., q_auto:good
) is supported within named transformations.
- Save-Data support is a feature included in the Client-Hints standard, which is already supported by Chrome and Opera browsers. The browsers send a special request header named 'Save-Data' if the user has enabled data saving mode. When
q_auto
is specified and the 'Save-Data: on' header reaches the CDN layer of Cloudinary, image compression and encoding will automatically switch to the eco
mode (q_auto:eco
) instead of the default good
quality mode (q_auto:good
).
- Override automatic quality: you can override the automatic quality algorithm and set a fixed quality value for a specific image in the media library.
Chroma subsampling is a method of encoding images by implementing less resolution for chroma information (colors) than for luma information (luminance), taking advantage of the human visual system's lower acuity for color differences than for luminance. To override the default behavior of whether to perform chroma subsampling, a separate value can be added to the quality parameter as follows:
444
can be added to prevent subsampling. For example: q_80:444
420
can be added to force subsampling. For example: q_95:420
.
Chroma subsampling is not performed on images that include a text overlay unless specifically requested.
Cloudinary supports various transformations for modifying the shape and style of images. This section contains information on the following topics:
Many website designs need images with rounded corners, while some websites require images with a complete circular or oval (ellipse) crop. Twitter, for example, uses rounded corners for its users' profile pictures.
Programmatically, rounded corners can be achieved using the original rectangular images combined with modern CSS properties or image masking overlays. However, it is sometimes useful to deliver images with rounded corners in the first place. This is particularly helpful when you want to embed images inside an email (most mail clients can't add CSS based rounded corners), a PDF or a mobile application. Delivering images with already rounded corners is also useful if you want to simplify your CSS and markup or when you need to support older browsers.
Transforming an image to a rounded version is done using the radius
parameter (r
in URLs). You can manually specify the amount to round various corners, or you can set it to automatically round to an exact ellipse or circle.
To deliver a rounded image with a transparent background, deliver as PNG. Formats that do not support transparency will be delivered by default with a white background, which can be adjusted with the
background
transformation parameter. Keep in mind that the PNG format produces larger files than the JPEG format. For more information, see the article on
PNG optimization - saving bandwidth on transparent PNGs with dynamic underlay.
To manually control the rounding, use the radius
parameter with between 1 and 4 values defining the rounding amount (in pixels, separated by colons), following the same concept as the border-radius CSS property. When specifying multiple values, keep a corner untouched by specifying '0'.
- One value: Symmetrical. All four corners are rounded equally according to the specified value.
- Two values: Opposites are symmetrical. The first value applies to the top-left and bottom-right corners. The second value applies to the top-right and bottom-left corners.
- Three values: One set of corners is symmetrical. The first value applies to the top-left. The second value applies to the top-right and bottom-left corners. The third value applies to the bottom-right.
- Four values: The rounding for each corner is specified separately, in clockwise order, starting with the top-left.
For example:
r_20
r_25:0
r_10:40:25
r_30:0:30:30
Ruby:
cl_image_tag("Pi.png", :width=>150, :height=>100, :radius=>"25:0", :crop=>"fill")
PHP:
cl_image_tag("Pi.png", array("width"=>150, "height"=>100, "radius"=>"25:0", "crop"=>"fill"))
Python:
CloudinaryImage("Pi.png").image(width=150, height=100, radius="25:0", crop="fill")
Node.js:
cloudinary.image("Pi.png", {width: 150, height: 100, radius: "25:0", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(150).height(100).radius("25:0").crop("fill")).imageTag("Pi.png");
JS:
cloudinary.imageTag('Pi.png', {width: 150, height: 100, radius: "25:0", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("Pi.png", {width: 150, height: 100, radius: "25:0", crop: "fill"})
React:
<Image publicId="Pi.png" >
<Transformation width="150" height="100" radius="25:0" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="Pi.png" >
<cld-transformation width="150" height="100" radius="25:0" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="Pi.png" >
<cl-transformation width="150" height="100" radius="25:0" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(100).Radius("25:0").Crop("fill")).BuildImageTag("Pi.png")
Android:
MediaManager.get().url().transformation(new Transformation().width(150).height(100).radius("25:0").crop("fill")).generate("Pi.png");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setHeight(100).setRadius("25:0").setCrop("fill")).generate("Pi.png")!, cloudinary: cloudinary)
Rather than specifying specific rounding values, you can automatically crop images to the shape of an ellipse (if the requested image size is a rectangle) or a circle (if the requested image size is a square). Simply pass max
as the value of the radius
parameter instead of numeric values.
The following example transforms an uploaded JPEG to a 250x150 PNG with maximum radius cropping, which generates the ellipse shape with a transparent background:
Ruby:
cl_image_tag("pi.png", :width=>250, :height=>150, :radius=>"max", :crop=>"fill")
PHP:
cl_image_tag("pi.png", array("width"=>250, "height"=>150, "radius"=>"max", "crop"=>"fill"))
Python:
CloudinaryImage("pi.png").image(width=250, height=150, radius="max", crop="fill")
Node.js:
cloudinary.image("pi.png", {width: 250, height: 150, radius: "max", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(250).height(150).radius("max").crop("fill")).imageTag("pi.png");
JS:
cloudinary.imageTag('pi.png', {width: 250, height: 150, radius: "max", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("pi.png", {width: 250, height: 150, radius: "max", crop: "fill"})
React:
<Image publicId="pi.png" >
<Transformation width="250" height="150" radius="max" crop="fill" />
</Image>
Vue.js:
<cld-image publicId="pi.png" >
<cld-transformation width="250" height="150" radius="max" crop="fill" />
</cld-image>
Angular:
<cl-image public-id="pi.png" >
<cl-transformation width="250" height="150" radius="max" crop="fill">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(250).Height(150).Radius("max").Crop("fill")).BuildImageTag("pi.png")
Android:
MediaManager.get().url().transformation(new Transformation().width(250).height(150).radius("max").crop("fill")).generate("pi.png");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(250).setHeight(150).setRadius("max").setCrop("fill")).generate("pi.png")!, cloudinary: cloudinary)
As the following example shows, displaying pictures of your web site's users as circle headshots is very easy to achieve with Cloudinary using face
gravity with max
radius:
Ruby:
cl_image_tag("face_left.png", :width=>200, :height=>200, :gravity=>"face", :radius=>"max", :crop=>"thumb")
PHP:
cl_image_tag("face_left.png", array("width"=>200, "height"=>200, "gravity"=>"face", "radius"=>"max", "crop"=>"thumb"))
Python:
CloudinaryImage("face_left.png").image(width=200, height=200, gravity="face", radius="max", crop="thumb")
Node.js:
cloudinary.image("face_left.png", {width: 200, height: 200, gravity: "face", radius: "max", crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().width(200).height(200).gravity("face").radius("max").crop("thumb")).imageTag("face_left.png");
JS:
cloudinary.imageTag('face_left.png', {width: 200, height: 200, gravity: "face", radius: "max", crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("face_left.png", {width: 200, height: 200, gravity: "face", radius: "max", crop: "thumb"})
React:
<Image publicId="face_left.png" >
<Transformation width="200" height="200" gravity="face" radius="max" crop="thumb" />
</Image>
Vue.js:
<cld-image publicId="face_left.png" >
<cld-transformation width="200" height="200" gravity="face" radius="max" crop="thumb" />
</cld-image>
Angular:
<cl-image public-id="face_left.png" >
<cl-transformation width="200" height="200" gravity="face" radius="max" crop="thumb">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(200).Height(200).Gravity("face").Radius("max").Crop("thumb")).BuildImageTag("face_left.png")
Android:
MediaManager.get().url().transformation(new Transformation().width(200).height(200).gravity("face").radius("max").crop("thumb")).generate("face_left.png");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(200).setHeight(200).setGravity("face").setRadius("max").setCrop("thumb")).generate("face_left.png")!, cloudinary: cloudinary)
You can also overlay circular pictures of your users on other images using the layer_apply
flag that tells Cloudinary to apply the rounding (and other transformations) to the overlay image and not to the base image:
Ruby:
cl_image_tag("flower.jpg", :transformation=>[
{:width=>200, :height=>200, :gravity=>"face", :radius=>"max", :overlay=>"face_left", :crop=>"thumb"},
{:flags=>"layer_apply", :gravity=>"north_east"}
])
PHP:
cl_image_tag("flower.jpg", array("transformation"=>array(
array("width"=>200, "height"=>200, "gravity"=>"face", "radius"=>"max", "overlay"=>"face_left", "crop"=>"thumb"),
array("flags"=>"layer_apply", "gravity"=>"north_east")
)))
Python:
CloudinaryImage("flower.jpg").image(transformation=[
{'width': 200, 'height': 200, 'gravity': "face", 'radius': "max", 'overlay': "face_left", 'crop': "thumb"},
{'flags': "layer_apply", 'gravity': "north_east"}
])
Node.js:
cloudinary.image("flower.jpg", {transformation: [
{width: 200, height: 200, gravity: "face", radius: "max", overlay: "face_left", crop: "thumb"},
{flags: "layer_apply", gravity: "north_east"}
]})
Java:
cloudinary.url().transformation(new Transformation()
.width(200).height(200).gravity("face").radius("max").overlay(new Layer().publicId("face_left")).crop("thumb").chain()
.flags("layer_apply").gravity("north_east")).imageTag("flower.jpg");
JS:
cloudinary.imageTag('flower.jpg', {transformation: [
{width: 200, height: 200, gravity: "face", radius: "max", overlay: new cloudinary.Layer().publicId("face_left"), crop: "thumb"},
{flags: "layer_apply", gravity: "north_east"}
]}).toHtml();
jQuery:
$.cloudinary.image("flower.jpg", {transformation: [
{width: 200, height: 200, gravity: "face", radius: "max", overlay: new cloudinary.Layer().publicId("face_left"), crop: "thumb"},
{flags: "layer_apply", gravity: "north_east"}
]})
React:
<Image publicId="flower.jpg" >
<Transformation width="200" height="200" gravity="face" radius="max" overlay="face_left" crop="thumb" />
<Transformation flags="layer_apply" gravity="north_east" />
</Image>
Vue.js:
<cld-image publicId="flower.jpg" >
<cld-transformation width="200" height="200" gravity="face" radius="max" overlay="face_left" crop="thumb" />
<cld-transformation flags="layer_apply" gravity="north_east" />
</cld-image>
Angular:
<cl-image public-id="flower.jpg" >
<cl-transformation width="200" height="200" gravity="face" radius="max" overlay="face_left" crop="thumb">
</cl-transformation>
<cl-transformation flags="layer_apply" gravity="north_east">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(200).Height(200).Gravity("face").Radius("max").Overlay(new Layer().PublicId("face_left")).Crop("thumb").Chain()
.Flags("layer_apply").Gravity("north_east")).BuildImageTag("flower.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.width(200).height(200).gravity("face").radius("max").overlay(new Layer().publicId("face_left")).crop("thumb").chain()
.flags("layer_apply").gravity("north_east")).generate("flower.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setWidth(200).setHeight(200).setGravity("face").setRadius("max").setOverlay("face_left").setCrop("thumb").chain()
.setFlags("layer_apply").setGravity("north_east")).generate("flower.jpg")!, cloudinary: cloudinary)
Rotate an image by any arbitrary angle in degrees with the angle
parameter (a
in URLs). A positive integer value rotates the image clockwise, and a negative integer value rotates the image counterclockwise. If the angle is not a multiple of 90 then a rectangular bounding box is added containing the rotated image and empty space.
If either the width or height of an image exceeds 3000 pixels, the image is automatically downscaled first, and then rotated. This applies to the image that is the input to the rotation, be it the output of a chained transformation or the original image.
Other possible rotation values instead of an integer value include:
auto_right
- Rotate the image 90 degrees clockwise only if the requested aspect ratio does not match the image's aspect ratio.
auto_left
- Rotate the image 90 degrees counterclockwise only if the requested aspect ratio does not match the image's aspect ratio.
vflip
- Vertical mirror flip of the image.
hflip
- Horizontal mirror flip of the image.
ignore
- By default, the image is automatically rotated according to the EXIF data stored by the camera when the image was taken. Set the rotation to 'ignore' if you do not want the image to be automatically rotated.
To apply multiple values, separate each value with a dot (
.
). For example to horizontally flip the image and rotate it by 45 degrees:
angle: hflip.45
Examples with the uploaded image named sample
(all images are also scaled down to a width of 100 pixels):
- Rotate the image by 90 degrees:
Ruby:
cl_image_tag("sample.jpg", :transformation=>[
{:width=>100, :crop=>"scale"},
{:angle=>90}
])
PHP:
cl_image_tag("sample.jpg", array("transformation"=>array(
array("width"=>100, "crop"=>"scale"),
array("angle"=>90)
)))
Python:
CloudinaryImage("sample.jpg").image(transformation=[
{'width': 100, 'crop': "scale"},
{'angle': 90}
])
Node.js:
cloudinary.image("sample.jpg", {transformation: [
{width: 100, crop: "scale"},
{angle: 90}
]})
Java:
cloudinary.url().transformation(new Transformation()
.width(100).crop("scale").chain()
.angle(90)).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {transformation: [
{width: 100, crop: "scale"},
{angle: 90}
]}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {transformation: [
{width: 100, crop: "scale"},
{angle: 90}
]})
React:
<Image publicId="sample.jpg" >
<Transformation width="100" crop="scale" />
<Transformation angle="90" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="100" crop="scale" />
<cld-transformation angle="90" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="100" crop="scale">
</cl-transformation>
<cl-transformation angle="90">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(100).Crop("scale").Chain()
.Angle(90)).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.width(100).crop("scale").chain()
.angle(90)).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setWidth(100).setCrop("scale").chain()
.setAngle(90)).generate("sample.jpg")!, cloudinary: cloudinary)
- Rotate the image by -20 degrees (automatically adds a bounding box):
Ruby:
cl_image_tag("sample.jpg", :transformation=>[
{:width=>100, :crop=>"scale"},
{:angle=>-20}
])
PHP:
cl_image_tag("sample.jpg", array("transformation"=>array(
array("width"=>100, "crop"=>"scale"),
array("angle"=>-20)
)))
Python:
CloudinaryImage("sample.jpg").image(transformation=[
{'width': 100, 'crop': "scale"},
{'angle': -20}
])
Node.js:
cloudinary.image("sample.jpg", {transformation: [
{width: 100, crop: "scale"},
{angle: -20}
]})
Java:
cloudinary.url().transformation(new Transformation()
.width(100).crop("scale").chain()
.angle(-20)).imageTag("sample.jpg");
JS:
cloudinary.imageTag('sample.jpg', {transformation: [
{width: 100, crop: "scale"},
{angle: -20}
]}).toHtml();
jQuery:
$.cloudinary.image("sample.jpg", {transformation: [
{width: 100, crop: "scale"},
{angle: -20}
]})
React:
<Image publicId="sample.jpg" >
<Transformation width="100" crop="scale" />
<Transformation angle="-20" />
</Image>
Vue.js:
<cld-image publicId="sample.jpg" >
<cld-transformation width="100" crop="scale" />
<cld-transformation angle="-20" />
</cld-image>
Angular:
<cl-image public-id="sample.jpg" >
<cl-transformation width="100" crop="scale">
</cl-transformation>
<cl-transformation angle="-20">
</cl-transformation>
</cl-image>
.NET:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
.Width(100).Crop("scale").Chain()
.Angle(-20)).BuildImageTag("sample.jpg")
Android:
MediaManager.get().url().transformation(new Transformation()
.width(100).crop("scale").chain()
.angle(-20)).generate("sample.jpg");
iOS:
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
.setWidth(100).setCrop("scale").chain()
.setAngle(-20)).generate("sample.jpg")!, cloudinary: cloudinary)
- Vertically mirror flip the image and rotate by 45 degrees (automatically adds a bounding box):
Ruby:
cl_image_tag("sample.jpg", :transformation=>[
{:width=>100, :crop=>"scale"},
{:angle=>["vflip", 45]}
])
PHP:
cl_image_tag("sample.jpg", array("transformation"=>array(
array("width"=>100, "crop"=>"scale"),
array("angle"=>array("vflip", 45))
)))
Python:
CloudinaryImage("sample.jpg").image(transformation=[
{'width': 100, 'crop': "scale"},
{'angle': ["vflip", 45]}
])