Programmable Media

JavaScript SDK (Legacy)

Last updated: Jun-04-2024

Important
This is the legacy version of the JavaScript SDK (cloudinary-core v2.x).

For details on migrating to the current version of the SDK (js-url-gen v1.x), see the JavaScript SDK migration guide.

Overview

Cloudinary's JavaScript SDK provides simple, yet comprehensive image and video upload, transformation, optimization, and delivery capabilities that you can implement using code that integrates seamlessly with your existing JavaScript application.

Related topics
This guide relates to the latest released version of the JavaScript cloudinary-core v2.x library.

For details on all new features and fixes from previous minor versions, see the CHANGELOG.

On this page:

Note
This guide describes Cloudinary's JavaScript cloudinary-core frontend library. For the backend Node.js library, see the Node.js documentation.

Quick example

Take a look at the following transformation code and the image it delivers:

sample transformation

This relatively simple code performs all of the following on the original front_face.jpg image before delivering it:

  • Crop to a 150x150 thumbnail using face-detection gravity to automatically determine the location for the crop
  • Round the corners with a 20 pixel radius
  • Apply a sepia effect
  • Overlay the Cloudinary logo on the southeast corner of the image (with a slight offset). The logo is scaled down to a 50 pixel width, with increased brightness and partial transparency (opacity = 60%)
  • Rotate the resulting image (including the overlay) by 10 degrees
  • Convert and deliver the image in PNG format (the originally uploaded image was a JPG)

And here's the URL that would be included in the image tag that's automatically generated from the above code:

In a similar way, you can transform a video.

Learn more about transformations

JavaScript SDK features

  • Build URLs for image and video transformation
  • JavaScript view helper tags for embedding and transforming images, and more

Get started

This section describes the information you need to know for installing and setting up JavaScript.

Installation

Install the files using the NPM package manager:

Note
Instead of installing the files, the latest minor version of the cloudinary-core library can also be directly referenced from https://unpkg.com/cloudinary-core@latest. For production use, we recommend that you use a specific version, and not the latest, to protect yourself from any breaking changes.

Setup

1. Instantiate the cloudinary-core library

If you installed the files with NPM, instantiate a new variable with the cloudinary-core library within your code.

Or, if using ES6 or higher without a bundler, for example, in a script:

Otherwise, you can include the files in your in your HTML page. For Example:

2. Set Cloudinary configuration parameters

To use the Cloudinary cloudinary-core library you have to configure at least your product environment cloud_name. You can additionally define a number of optional configuration parameters if relevant. You can find your Cloud name in the Programmable Media Dashboard of the Cloudinary Console, and you can find all of your credentials, including API Key and API Secret, on the API Keys page of the Cloudinary Console Settings.

Notes
  • Most functionality implemented on the client side does not require authentication, so only your cloud_name is required to be configured, and not your API key or secret. Your API secret should never be exposed on the client side, so if you want to use signed uploads or generate delivery signatures, you'll also need server-side code, for which you can use one of our backend SDKs.
  • For backward compatibility reasons, the default value of the optional secure configuration parameter is false. However, for most modern applications, it's recommended to configure the secure parameter to true to ensure that your transformation URLs are always generated as HTTPS.

You set configuration parameters while instantiating a new Cloudinary class, for example:

  • If using import {Cloudinary} from "cloudinary-core";:
  • If using var cloudinary = require("cloudinary-core"); or <script src="/cloudinary-core/cloudinary-core.js"...:

JavaScript capitalization and data type guidelines

When using the cloudinary-core library, keep these guidelines in mind:

  • Parameter names: snake_case. For example: public_id
  • Classes: PascalCase. For example: ImageTag
  • Methods: camelCase. For example: toHTML
  • Pass parameter data as: Object

✔️ Feedback sent!

Rate this page: