Global

Methods

cacheResults(result, options)

Cache (part of) the upload results.
Parameters:
Name Type Description
result
options object
Properties
Name Type Description
type string
resource_type string
Source:

(private) chainTransformations(options, transformation)

Helper function, allows chaining transformation to the end of transformation list
Parameters:
Name Type Description
options object Original options
transformation object | Array.<object> Transformations to chain at the end
Source:
Returns:
array Resulting options

(private) crc32(str) → {number|*}

Compute the crc32 checksum if the given string
Parameters:
Name Type Description
str string
Source:
Returns:
Type
number | *

(private) defaults(defaults) → {function}

Returns an ensureOption function that relies on the provided `defaults` argument for default values.
Parameters:
Name Type Description
defaults object
Source:
Returns:
Type
function

(private) ensurePresenceOf(parameters)

Validate that the given values are defined
Parameters:
Name Type Description
parameters object where each key value pair is the name and value of the argument to validate.
Source:
Example
function foo(bar){
     ensurePresenceOf({bar});
     // ...
   }

(private) generateImageResponsiveAttributes(publicId, attributes, srcsetData, options)

Helper function. Generates srcset and sizes attributes of the image tag Generated attributes are added to attributes argument
Parameters:
Name Type Description
publicId string The public ID of the resource
attributes object Existing HTML attributes.
srcsetData srcset
options object Additional options.
Source:
Returns:
array The responsive attributes

(private) generateMediaAttr(options) → {string}

Generate a media query
Parameters:
Name Type Description
options object configuration options
Properties
Name Type Description
min_width number | string
max_width number | string
Source:
Returns:
a media query string
Type
string

(private) generateSizesAttribute(srcsetData) → {string}

Helper function. Generates sizes attribute value of the HTML img tag
Parameters:
Name Type Description
srcsetData object | string
Properties
Name Type Attributes Description
breakpoints Array.<number> <optional>
An array of breakpoints.
min_width number <optional>
Minimal width of the srcset images.
max_width number <optional>
Maximal width of the srcset images.
max_images number <optional>
Number of srcset images to generate.
Source:
Returns:
Resulting sizes attribute value
Type
string

(private) generateSrcsetAttribute(public_id, breakpoints, transformation, options) → {string}

Helper function. Generates srcset attribute value of the HTML img tag
Parameters:
Name Type Description
public_id string Public ID of the resource
breakpoints Array.<number> An array of breakpoints (in pixels)
transformation object The transformation
options object Includes html tag options, transformation options
Source:
Returns:
Resulting srcset attribute value
Type
string

get() → {CacheAdapter}

Source:
Returns:
The current cache adapter
Type
CacheAdapter

getOrGenerateBreakpoints(srcset, public_id, options) → {*|Array}

If cache is enabled, get the breakpoints from the cache. If the values were not found in the cache, or cache is not enabled, generate the values.
Parameters:
Name Type Description
srcset srcset The srcset configuration parameters
public_id string
options object
Source:
Returns:
Type
* | Array

image(source, options) → {string}

Generate an HTML img tag with a Cloudinary URL
Parameters:
Name Type Description
source string A Public ID or a URL
options object Configuration options
Properties
Name Type Description
srcset srcset srcset options
attributes object HTML attributes
html_width number (deprecated) The HTML tag width
html_height number (deprecated) The HTML tag height
client_hints boolean Don't implement the client side responsive function. This argument can override the the same option in the global configuration.
responsive boolean Setup the tag for the client side responsive function.
hidpi boolean Setup the tag for the client side auto dpr function.
responsive_placeholder boolean A place holder image URL to use with the client side responsive function
Source:
Returns:
An HTML img tag
Type
string

module:auth_token(options) → {string}

Generate an authorization token
Parameters:
Name Type Description
options authTokenOptions
Source:
Returns:
the authorization token
Type
string

picture(public_id, options) → {string}

Generate a picture HTML tag.
The sources argument defines different transformations to apply for each media query.
Parameters:
Name Type Description
public_id string
options object
Properties
Name Type Description
sources Array.<object> a list of source arguments. A source tag will be rendered for each item
Properties
Name Type Description
min_width number a minimum width query
max_width number a maximum width query
transformation number the transformation to apply to the source tag.
Source:
Returns:
A picture HTML tag
Type
string
Example
cloudinary.picture("sample", {
  sources: [
    {min_width: 1600, transformation: {crop: 'fill', width: 800, aspect_ratio: 2}},
    {min_width: 500, transformation: {crop: 'fill', width: 600, aspect_ratio: 2.3}},
    {transformation: {crop: 'crop', width: 400, gravity: 'auto'}},
    ]}
);

rimraf(dir_path)

Remove directory recursively
Parameters:
Name Type Description
dir_path string
Source:
See:

set(adapter)

Set the cache adapter to be used by Cache
Parameters:
Name Type Description
adapter CacheAdapter Cache adapter
Source:

source(public_id, options) → {string}

Generate a source tag.
Parameters:
Name Type Description
public_id string
options object
Properties
Name Type Description
srcset srcset arguments required to generate the srcset attribute.
attributes object HTML tag attributes
Source:
Returns:
Type
string

(private) srcsetUrl(public_id, width, transformation, options) → {string}

Helper function. Generates a single srcset item url
Parameters:
Name Type Description
public_id string Public ID of the resource.
width number Width in pixels of the srcset item.
transformation object | string
options object Additional options.
Source:
Returns:
Resulting URL of the item
Type
string

video(public_id, optionsopt) → {string}

Creates an HTML video tag for the provided public_id
Parameters:
Name Type Attributes Description
public_id String the resource public ID
options Object <optional>
options for the resource and HTML tag
Properties
Name Type Attributes Description
source_types String | Array.<String> <optional>
Specify which source type the tag should include. defaults to webm, mp4 and ogv.
source_transformation String <optional>
specific transformations to use for a specific source type.
poster String | Object <optional>
image URL or poster options that may include a public_id key and poster-specific transformations
Source:
Returns:
HTML video tag
Type
string
Example

Example of generating a video tag:

cloudinary.video("mymovie.mp4");
cloudinary.video("mymovie.mp4", {source_types: 'webm'});
cloudinary.video("mymovie.ogv", {poster: "myspecialplaceholder.jpg"});
cloudinary.video("mymovie.webm", {source_types: ['webm', 'mp4'], poster: {effect: 'sepia'}});

Type Definitions

srcset

Options used to generate the srcset attribute.
Type:
  • object
Properties:
Name Type Attributes Description
breakpoints Array.<number> | Array.<string> <optional>
An array of breakpoints.
min_width number <optional>
Minimal width of the srcset images.
max_width number <optional>
Maximal width of the srcset images.
max_images number <optional>
Number of srcset images to generate.
transformation object | string <optional>
The transformation to use in the srcset urls.
sizes boolean <optional>
Whether to calculate and add the sizes attribute.
Source: