Cloudflare Docs
Cloudflare Image Optimization
Edit this page
Report an issue with this page
Log into the Cloudflare dashboard
Set theme to dark (⇧+D)

Create variants

Variants let you specify how images should be resized for different use cases. By default, images are served with a public variant, but you can create up to 100 variants to fit your needs. Follow these steps to create a variant.

  1. Log in to the Cloudflare dashboard and select your account.
  2. Select Images > Variants.
  3. Name your variant and select Add New Variant.
  4. Define variables for your new variant, such as resizing options, type of fit, and specific metadata options.

​​ Resize via the API

Make a POST request to create a variant.

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/images/v1/variants" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{"id":"<NAME_OF_THE_VARIANT>","options":{"fit":"scale-down","metadata":"none","width":1366,"height":768},"neverRequireSignedURLs":true}

​​ Fit options

The Fit property describes how the width and height dimensions should be interpreted. The chart below describes each of the options.

Fit OptionsBehavior
Scale downThe image is shrunk in size to fully fit within the given width or height, but will not be enlarged.
ContainThe image is resized (shrunk or enlarged) to be as large as possible within the given width or height while preserving the aspect ratio.
CoverThe image is resized to exactly fill the entire area specified by width and height and will be cropped if necessary.
CropThe image is shrunk and cropped to fit within the area specified by the width and height. The image will not be enlarged. For images smaller than the given dimensions, it is the same as scale-down. For images larger than the given dimensions, it is the same as cover.
PadThe image is resized (shrunk or enlarged) to be as large as possible within the given width or height while preserving the aspect ratio. The extra area is filled with a background color (white by default).

​​ Metadata options

Variants allow you to choose what to do with your image’s metadata information. From the Metadata dropdown, choose:

  • Strip all metadata
  • Strip all metadata except copyright
  • Keep all metadata

​​ Public access

When the Always allow public access option is selected, particular variants will always be publicly accessible, even when images are made private through the use of signed URLs.