Image optimization

Optimizing your images is important for improving performance for your website or application.

This page provides an overview of considerations that can impact image optimization and covers the various Cloudinary optimization features and options you can use to make sure your images are delivered to your users in the quickest and best way possible, a key component in improving Core Web Vitals metrics.

What is image optimization?

Optimizing an image involves delivering images in the format, dimensions, resolution, and quality that will yield the smallest possible file size while ensuring that the resulting image is appropriate for the specific content, the overall page design, the requesting device, and the expectations of your site visitors.

The following table summarizes the main elements that impact image file size and potential solutions for addressing those issues. However, in many cases, implementing the solutions on your own can be very time or labor intensive. Click the link on each issue to learn how to use Cloudinary functionality to implement these solutions with minimal or no coding.

Issue Problem Possible Solutions
Image quality Often photographs are delivered at their original extra-high resolution, for fear of losing too much visual quality or to make sure users with high-res (retina display and DPR 2+) devices will get the quality they expect. The result is a huge file and slow delivery speeds. In most cases, you can significantly lower quality without a significant visual impact. Consider your image purpose and audience, and use the lowest possible quality that is acceptable for the image content, audience, and purpose.

When it’s important to deliver top-quality images for high-res devices, use the <picture> element and its srcset attribute to deliver different resolutions for different devices.

Image format
  • All image formats use some form of image compression. Some image formats are also lossy, meaning they discard some pixel data. Lossy formats work quite well for some image content, but not for others.
  • Different browsers support a variety of formats that may be more efficient than the standard JPG, PNG, and GIF formats. Delivering the standard formats for all browsers misses out on valuable savings from newer formats like AVIF and WebP.
  • Small images, like buttons and logos are often a larger percentage of site images than designers realize and many appear on every page. These types of images don’t look good in lossy formats, but delivering them as PNGs results in a large cumulative size for these images, which can slow your page load time.
  • Make sure each image is delivered in the right format for its image content.
  • Take advantage of CDN services or other tools/logic to check which browser is making the request and deliver different formats for different browsers using the <picture> element and its srcset attribute.
  • Instead of large animated GIFs, deliver animated WebP or use JPEG-XR (with CSS Animations (using the step property) to supported browsers, or convert to an MP4. You can also consider delivering lossy animated GIFs to get a smaller file when image quality is not a top priority.
  • Vector graphics (SVG) are based on line, point, and shape markup, rather than pixels. Using vectors for geometric graphics, enables sharp results at every resolution and zoom, with a minimal file size.
  • CSS3 effects and animations along with web fonts can sometimes be used to produce resolution-independent resources at a fraction of the size of the corresponding image.
  • Image Sprites: When vectors and CSS3 cannot replace raster images, using a single CSS image sprite, rather than many images, reduces server requests and thus saves bandwidth.
Image metadata By default, images contain a lot of metadata stored by cameras and graphics applications, but this data is completely unnecessary in delivered images. As a best practice, keep the metadata in your original copy of the graphics, but remove it in delivered images.
Image sizing and resizing If you need to display an image at a size smaller than the original, and you rely on the browser to resize images, then you are delivering unnecessarily large files.

This applies both to a standard image resize, and responsive design, which requires multiple different images sizes.

The required dimensions can be determined on the server side (before it is delivered to the browser).

For responsive design, use the <picture> element and its srcset attribute to deliver different size images at different breakpoints.

Even when resizing on the server side, keep in mind that you can crop to focus on important content, and not just scale down your images.

Default optimizations

Whenever you apply any transformation to an image, Cloudinary performs the following optimizations by default:

  • Strips all associated metadata from the transformed image file, except the following:

    • JFIFVersion
    • ResolutionUnit
    • XResolution
    • YResolution
    • Colorspace
    • DPI

    To override this behavior and deliver a transformed image with all of its metadata intact, add the fl_keep_iptc flag. Alternatively, you can use the fl_keep_attribution flag to keep the copyright-related metadata in the transformed image, but still strip the other metadata content that gets stripped by default.

  • Applies automatic optimization and quality adjustments to generated images. To override the default adjustments, set the quality parameter in your transformation.

Note
Each of the default optimizations affect only the transformed image. The original image file remains unchanged.

How to optimize image quality

The image quality setting defines the compression level to apply to an image as a value between 1 (smallest file size) and 100 (best visual quality).

The setting you choose entails 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, and the more data is lost in the process, the result of which is a loss of visual quality. At the higher quality levels, the loss of visual quality is barely noticeable to the human eye. The ultimate visual quality result also depends on other factors such as the size of the original image and the resolution of the user's monitor or mobile screen.

Adjusting the quality of your images to a level that still provides good visual output, is one of the most powerful tools in image optimization. You can often deliver images at less than half of the original file size with little to no visually noticeable difference. Optimizing image quality can also help improve your Core Web Vitals score.

There are a few ways to control the quality of images delivered from Cloudinary:

Set the default quality for your account

As mentioned above, when you deliver an image with any transformation applied, it also applies a default quality level. Depending on the content, purpose, and audience for the majority of your images, you may want to modify the Default image quality level in the Upload Settings for your account.

You can choose a fixed quality level, or use one of the q_auto options as the default.

When you want specific image transformations to use a quality setting that is different to the default set for your account, or if you are not performing any other transformations on an image you deliver, you can specify the quality level as a transformation.

For example, the q_60 parameter below decreases the delivered file size from 118 KB to 73 KB:

Ruby:
Copy to clipboard
cl_image_tag("sample.jpg", :quality=>60)
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("sample.jpg", array("quality"=>60))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('sample.jpg'))
  ->delivery(Delivery::quality(60));
Python:
Copy to clipboard
CloudinaryImage("sample.jpg").image(quality=60)
Node.js:
Copy to clipboard
cloudinary.image("sample.jpg", {quality: 60})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().quality(60)).imageTag("sample.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('sample.jpg', {quality: 60}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("sample.jpg", {quality: 60})
React:
Copy to clipboard
<Image publicId="sample.jpg" >
  <Transformation quality="60" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="sample.jpg" >
  <cld-transformation quality="60" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="sample.jpg" >
  <cl-transformation quality="60">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality(60)).BuildImageTag("sample.jpg")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality(60)).generate("sample.jpg")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().quality(60)).generate("sample.jpg");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("sample.jpg")
delivery(Delivery.quality(60))
}.generate()
Image set at 60% quality

Set the quality when delivering an image

Control the visual quality and compression level of 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:
Copy to clipboard
cl_image_tag("sample.jpg", :quality=>60)
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("sample.jpg", array("quality"=>60))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('sample.jpg'))
  ->delivery(Delivery::quality(60));
Python:
Copy to clipboard
CloudinaryImage("sample.jpg").image(quality=60)
Node.js:
Copy to clipboard
cloudinary.image("sample.jpg", {quality: 60})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().quality(60)).imageTag("sample.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('sample.jpg', {quality: 60}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("sample.jpg", {quality: 60})
React:
Copy to clipboard
<Image publicId="sample.jpg" >
  <Transformation quality="60" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="sample.jpg" >
  <cld-transformation quality="60" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="sample.jpg" >
  <cl-transformation quality="60">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality(60)).BuildImageTag("sample.jpg")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality(60)).generate("sample.jpg")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().quality(60)).generate("sample.jpg");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("sample.jpg")
delivery(Delivery.quality(60))
}.generate()
Image with quality set to 60

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.

beach hut
Quality: 100 Size: 228KB
10 20 30 40 50 60 70 80 90 100

Notes

  • 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 blog post 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.

Toggle chroma subsampling

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.

Note
Chroma subsampling is not performed on images that include a text overlay unless specifically requested.

Automatic quality selection (q_auto)

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 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.

To perform automatic quality selection and image encoding adjustments, set the quality transformation parameter to auto (q_auto in URLs) or apply one of the Automatic options as the default image quality setting for your account.

You can further fine-tune the automatic quality selection 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 Original (569KB) q_80 q_80 (80.3KB) q_auto:best q_auto:best (65.9KB) q_auto:good q_auto:good (56.9KB) q_auto:eco q_auto:eco (45.0KB) q_auto:low q_auto:low (35.0KB)

Ruby:
Copy to clipboard
cl_image_tag("woman.jpg", :quality=>"auto")
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("woman.jpg", array("quality"=>"auto"))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('woman.jpg'))
  ->delivery(Delivery::quality(Quality::auto()));
Python:
Copy to clipboard
CloudinaryImage("woman.jpg").image(quality="auto")
Node.js:
Copy to clipboard
cloudinary.image("woman.jpg", {quality: "auto"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().quality("auto")).imageTag("woman.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('woman.jpg', {quality: "auto"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("woman.jpg", {quality: "auto"})
React:
Copy to clipboard
<Image publicId="woman.jpg" >
  <Transformation quality="auto" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="woman.jpg" >
  <cld-transformation quality="auto" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="woman.jpg" >
  <cl-transformation quality="auto">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality("auto")).BuildImageTag("woman.jpg")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality("auto")).generate("woman.jpg")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().quality("auto")).generate("woman.jpg");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("woman.jpg")
delivery(Delivery.quality(Quality.auto()))
}.generate()

Examples of the resulting file size when encoding a drawing, using regular and automatic quality values:

Original Original (296KB) q_80 q_80 (223KB) q_auto:best q_auto:best (226KB) q_auto:good q_auto:good (156KB) q_auto:eco q_auto:eco (97.5KB) q_auto:low q_auto:low (87.5KB)

Ruby:
Copy to clipboard
cl_image_tag("robot.jpg", :quality=>"auto")
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("robot.jpg", array("quality"=>"auto"))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('robot.jpg'))
  ->delivery(Delivery::quality(Quality::auto()));
Python:
Copy to clipboard
CloudinaryImage("robot.jpg").image(quality="auto")
Node.js:
Copy to clipboard
cloudinary.image("robot.jpg", {quality: "auto"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().quality("auto")).imageTag("robot.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('robot.jpg', {quality: "auto"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("robot.jpg", {quality: "auto"})
React:
Copy to clipboard
<Image publicId="robot.jpg" >
  <Transformation quality="auto" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="robot.jpg" >
  <cld-transformation quality="auto" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="robot.jpg" >
  <cl-transformation quality="auto">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Quality("auto")).BuildImageTag("robot.jpg")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setQuality("auto")).generate("robot.jpg")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().quality("auto")).generate("robot.jpg");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("robot.jpg")
delivery(Delivery.quality(Quality.auto()))
}.generate()

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.

beach hut
Quality: 100 Size: 228KB
auto:low auto:eco auto:good auto:best 80 100

Notes

  • 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).
  • You can set an override quality for a specific image in the Media Library Edit Asset page of that asset. When set, that quality will always override any q_auto setting specified in a URL for that asset. This can be useful to control the quality of an important image if you apply a q_auto default setting for your account, or if all images delivered through a particular process are delivered with a transformation that includes q_auto. Cloudinary also uses your overrides as input that can help it improve the q_auto algorithm.

See also: q_auto for video

How to optimize image format

Image formats can be lossy or lossless, each with its own compression algorithm. And as mentioned, each type gives better results on some types of image content, and poorer results on other types. Furthermore, some of the newer formats are only supported on some browsers. Optimizing image format can also help improve your Core Web Vitals score.

Choosing the right format to deliver each image can result in significant file size savings without sacrificing quality.

There are several Cloudinary options you can use to address these issues.

  • Even if your users upload images in a format that isn’t ideal for the content, you can easily deliver in them a different type, just by changing the file type extension in the delivery URL.
  • Use the automatic format selection (f_auto) transformation parameter to allow Cloudinary to analyze the image content and select the best format to deliver. For example, it can automatically deliver images as WebP, AVIF or JPEG-2000 to browsers that support those formats, while delivering in the original format to all other browsers. This option can also deliver animated GIFs as WebP on browsers that support this format.
  • For browsers that do not support WebP, you can also deliver animated GIFs as lossy GIFs, for significant file size savings while maintaining acceptable quality.

This lossy animated GIF is only 2.5 MB, compared to the 6.3 MB original:

Ruby:
Copy to clipboard
cl_image_tag("kitten_fighting", :flags=>"lossy")
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("kitten_fighting", array("flags"=>"lossy"))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('kitten_fighting'))
  ->delivery(Delivery::format(Format::gif())
    ->lossy());
Python:
Copy to clipboard
CloudinaryImage("kitten_fighting").image(flags="lossy")
Node.js:
Copy to clipboard
cloudinary.image("kitten_fighting", {flags: "lossy"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().flags("lossy")).imageTag("kitten_fighting");
JS:
Copy to clipboard
cloudinary.imageTag('kitten_fighting', {flags: "lossy"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("kitten_fighting", {flags: "lossy"})
React:
Copy to clipboard
<Image publicId="kitten_fighting" >
  <Transformation flags="lossy" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="kitten_fighting" >
  <cld-transformation flags="lossy" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="kitten_fighting" >
  <cl-transformation flags="lossy">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Flags("lossy")).BuildImageTag("kitten_fighting")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setFlags("lossy")).generate("kitten_fighting")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().flags("lossy")).generate("kitten_fighting");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("kitten_fighting")
delivery(Delivery.format(Format.gif()) {
lossy()
})
}.generate()
A lossy animated GIF

Another way to lower the cost of animated graphics is to deliver animated GIFs as videos. You can do this by simply changing the file type extension to .mp4 (or webm for Chrome, Android, and Opera) in the delivery URL.

For example, this mp4 is 95% smaller than the original animated GIF (319 KB instead of 6.3 MB):

Ruby:
Copy to clipboard
cl_video_tag("kitten_fighting", :resource_type=>"image")
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_video_tag("kitten_fighting", array("resource_type"=>"image"))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new VideoTag('kitten_fighting.mp4'))
  ->assetType(AssetType::IMAGE);
Python:
Copy to clipboard
CloudinaryImage("kitten_fighting").video()
Node.js:
Copy to clipboard
cloudinary.video("kitten_fighting", {resource_type: "image"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().resourceType("image").videoTag("kitten_fighting");
JS:
Copy to clipboard
cloudinary.imageTag('kitten_fighting').toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("kitten_fighting", {resource_type: "image"})
React:
Copy to clipboard
<Image publicId="kitten_fighting" resourceType="image">

</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="kitten_fighting" resource-type="image">

</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="kitten_fighting" resource-type="image">

</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.BuildVideoTag("kitten_fighting")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().generate("kitten_fighting.mp4")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().generate("kitten_fighting.mp4");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("kitten_fighting.mp4")
assetType("image")
}.generate()

For more information on working with animated GIFs, see Manipulating animated GIFs.

Automatic format selection (f_auto)

There are many 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 optimize delivery time and save bandwidth is 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. Depending on the browser and which formats are enabled for f_auto on your account, the image could be delivered as, for example, AVIF, WebP or JPEG-2000 (or animated WebP, if it is an animated image). If a browser does not support any of the optimized formats that f_auto is enabled to return, then the image is delivered in the format specified by the file extension.

For example, rather than the source format of JPEG (33.5 KB) being delivered for this scaled down image, depending on the browser, an AVIF (14.6 KB), WebP (16.1 KB) or JPEG-2000 (21.0 KB) could be delivered. The table shows other formats for comparison:

Ruby:
Copy to clipboard
cl_image_tag("docs/shoes.jpg", :transformation=>[
  {:width=>500, :crop=>"scale"},
  {:fetch_format=>:auto}
  ])
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("docs/shoes.jpg", array("transformation"=>array(
  array("width"=>500, "crop"=>"scale"),
  array("fetch_format"=>"auto")
  )))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('docs/shoes'))
  ->resize(Resize::scale()->width(500))
  ->delivery(Delivery::format(Format::auto()));
Python:
Copy to clipboard
CloudinaryImage("docs/shoes.jpg").image(transformation=[
  {'width': 500, 'crop': "scale"},
  {'fetch_format': "auto"}
  ])
Node.js:
Copy to clipboard
cloudinary.image("docs/shoes.jpg", {transformation: [
  {width: 500, crop: "scale"},
  {fetch_format: "auto"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .fetchFormat("auto")).imageTag("docs/shoes.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('docs/shoes.jpg', {transformation: [
  {width: 500, crop: "scale"},
  {fetchFormat: "auto"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("docs/shoes.jpg", {transformation: [
  {width: 500, crop: "scale"},
  {fetch_format: "auto"}
  ]})
React:
Copy to clipboard
<Image publicId="docs/shoes.jpg" >
  <Transformation width="500" crop="scale" />
  <Transformation fetchFormat="auto" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="docs/shoes.jpg" >
  <cld-transformation width="500" crop="scale" />
  <cld-transformation fetch-format="auto" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="docs/shoes.jpg" >
  <cl-transformation width="500" crop="scale">
  </cl-transformation>
  <cl-transformation fetch-format="auto">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(500).Crop("scale").Chain()
  .FetchFormat("auto")).BuildImageTag("docs/shoes.jpg")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
  .setWidth(500).setCrop("scale").chain()
  .setFetchFormat("auto")).generate("docs/shoes.jpg")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(500).crop("scale").chain()
  .fetchFormat("auto")).generate("docs/shoes.jpg");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("docs/shoes")
resize(Resize.scale() {
width(500)
})
delivery(Delivery.format(Format.auto()))
}.generate()

Shoes image delivered with f_auto
Format Size
AVIF 14.6 KB
GIF 98.0 KB
JPEG 33.5 KB
JPEG-2000 21.0 KB
JPEG-XR 17.3 KB
PNG 190.0 KB
WebP 16.1 KB

Tips and considerations for using f_auto

  • Transformation counts: Using f_auto may increase your transformation counts and storage usage, due to the different formats being derived for a single transformation URL. You can limit the number of potential delivery formats by contacting support.
  • Bandwidth usage: Generally, total bandwidth usage should decrease with use of f_auto due to the delivery of more optimized (smaller file size) media files. However, in some cases, you may experience increased bandwidth usage, particularly with email campaigns, due to the use of the "private" cache-control directive, which prevents intermediate caches from delivering potentially unsupported formats to requesting browsers.
  • AVIF format: To enable AVIF to be supported as a possible returned format for f_auto on your Cloudinary account, contact support.
    Note
    Small images (under 5000 pixels) are not automatically delivered as AVIF because the overhead of the file format outweighs the byte-savings of the optimized image.
  • Using f_auto with q_auto: When automatic format (f_auto) is used in the same URL as 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.
    • For JPEG images, if the automatic quality algorithm decides that no chroma subsampling should be performed, the WebP format is not selected because this lossy format always performs chroma subsampling, which might result in a lower visual quality for some images. The AVIF format could still be selected if this is supported by the requesting browser and enabled on your account.
  • Using developer tools for f_auto testing: Be aware that if using developer tools to emulate different browsers, Cloudinary may return a format that is unsupported by the main browser, so images may not display as expected. For example, if using Chrome dev tools to emulate an iPhone Safari browser, a JPEG-2000 may be returned, which Chrome does not support.
  • Using f_auto for transparent images: If f_auto is used to deliver an image that contains transparency, and the requesting browser does not support WebP or AVIF, then the image is delivered in PNG format instead of the JPEG format.
  • Using f_auto with fl_any_format: 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.
  • JPEG-2000: JPEG-2000 is automatically supported as a possible returned format for f_auto on Cloudinary accounts created after October 2019. To enable this option for older accounts, contact support.
  • JPEG-XR: JPEG-XR is supported as a possible returned format for f_auto only for Cloudinary accounts created before April 2021 and is no longer supported by default. To add or remove this option, contact support.

See also: f_auto for video

How to optimize image sizing

Web site art-design generally requires displaying images at a variety of sizes, often much smaller than the original.

If you deliver full size images and rely on browser-side resizing (using CSS or HTML width and height attributes), users are forced to unnecessarily download large images. Therefore, images should always be delivered from the server at their final size.

When you use any of the Cloudinary resizing transformations, the sizing (scaling/cropping) is performed on the server side, and the image is always delivered to the browser at the requested size.

For details on resizing transformations, see Resizing and cropping images.

In general, the time for resizing an image on-the-fly (the first time it is delivered via the CDN) is negligible, but if you are resizing a very large image or video, and every millisecond counts even for those first users, consider doing an eager or explicit transformation to pre-generate the transformed image.

Responsive image sizing

The importance of server-side resizing becomes that much more important if your Web site is responsive and needs to select an image size based on the current size of your browser or the resolution of your device.

By taking advantage of Cloudinary’s dpr_auto, w_auto, and other responsive image functionalities, you can ensure that you are delivering large or high-resolution images only to those users whose device resolution or browser size requires it, and you can create the many different sized images required, using simple transformations.

For example, to deliver the sample image cropped to an aspect ratio of 4:3 using the fill crop method, and then automatically scaled to the width available for the image in the responsive layout, and with a DPR value suitable for the user's device, use a statement like this:

Ruby:
Copy to clipboard
cl_image_tag("sample.jpg", :transformation=>[
  {:aspect_ratio=>"4:3", :crop=>"fill"},
  {:width=>"auto", :crop=>"scale"},
  {:dpr=>"auto"}
  ])
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("sample.jpg", array("transformation"=>array(
  array("aspect_ratio"=>"4:3", "crop"=>"fill"),
  array("width"=>"auto", "crop"=>"scale"),
  array("dpr"=>"auto")
  )))
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('sample.jpg'))
  ->resize(Resize::fill()->aspectRatio(AspectRatio::ar4X3()))
  ->resize(Resize::scale()->width('auto'))
  ->delivery(Delivery::dpr(Dpr::auto()));
Python:
Copy to clipboard
CloudinaryImage("sample.jpg").image(transformation=[
  {'aspect_ratio': "4:3", 'crop': "fill"},
  {'width': "auto", 'crop': "scale"},
  {'dpr': "auto"}
  ])
Node.js:
Copy to clipboard
cloudinary.image("sample.jpg", {transformation: [
  {aspect_ratio: "4:3", crop: "fill"},
  {width: "auto", crop: "scale"},
  {dpr: "auto"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .aspectRatio("4:3").crop("fill").chain()
  .width("auto").crop("scale").chain()
  .dpr("auto")).imageTag("sample.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('sample.jpg', {transformation: [
  {aspectRatio: "4:3", crop: "fill"},
  {width: "auto", crop: "scale"},
  {dpr: "auto"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("sample.jpg", {transformation: [
  {aspect_ratio: "4:3", crop: "fill"},
  {width: "auto", crop: "scale"},
  {dpr: "auto"}
  ]})
React:
Copy to clipboard
<Image publicId="sample.jpg" >
  <Transformation aspectRatio="4:3" crop="fill" />
  <Transformation width="auto" crop="scale" />
  <Transformation dpr="auto" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="sample.jpg" >
  <cld-transformation aspect-ratio="4:3" crop="fill" />
  <cld-transformation width="auto" crop="scale" />
  <cld-transformation dpr="auto" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="sample.jpg" >
  <cl-transformation aspect-ratio="4:3" crop="fill">
  </cl-transformation>
  <cl-transformation width="auto" crop="scale">
  </cl-transformation>
  <cl-transformation dpr="auto">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .AspectRatio("4:3").Crop("fill").Chain()
  .Width("auto").Crop("scale").Chain()
  .Dpr("auto")).BuildImageTag("sample.jpg")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
  .setAspectRatio("4:3").setCrop("fill").chain()
  .setWidth("auto").setCrop("scale").chain()
  .setDpr("auto")).generate("sample.jpg")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .aspectRatio("4:3").crop("fill").chain()
  .width("auto").crop("scale").chain()
  .dpr("auto")).generate("sample.jpg");
Kotlin:
Copy to clipboard
cloudinary.image {
publicId("sample.jpg")
resize(Resize.fill() {
aspectRatio(AspectRatio.ar4X3())
})
resize(Resize.scale() {
width("auto")
})
delivery(Delivery.dpr(Dpr.auto()))
}.generate()
Image using dpr_auto and w_auto

The above example will yield a 318 KB file on a DPR 2.0 device and 115 KB on a DPR 1.0 device.

For more details, on Cloudinary’s responsive design functionality, see Responsive images.

Additional tips for optimizing images

Sprites

A sprite is a single image that is comprised of many smaller images. The web page is modified to download only a single image from the server and the page’s HTML uses alternative CSS class names to point to the small images within the larger image.

This minimizes the number of images to download and thus the number of server communications required, resulting in faster image delivery.

You can quickly create a single sprite image and the corresponding CSS file comprising all images with a particular tag.

After ensuring all relevant images are sized and tagged as needed, reference the URLs: https://res.cloudinary.com/demo/image/sprite/mytag.css https://res.cloudinary.com/demo/image/sprite/mytag.png

For more details, see Sprite Generation.

Analytics

Even after employing as many automated optimization solutions as possible, you may find that specific original or derived images are still especially big bandwidth eaters.

Take a look at the Reports section of the Cloudinary console. There’s always a personalized tip at the top of the page based on your account’s usage. Then check out the Top bandwidth images or resources and the corresponding Top derived images and resources. Consider employing file-specific optimizations on these resources.

Top derived images listing

Scroll down to the Top Browsers to get an idea of how important each browser is to your users. This can give you insights on the relative value of using newer formats that are only supported on some browsers.

Top browsers graph

✔️ Feedback sent!

Rate this page: