Skip to content

Cloudinary

The image processing capabilities of the Cloudinary image CDN are supported by a helper function provided to you by this library.

Setup

Make sure you have the @responsive-image/cdn package installed:

bash
npm install @responsive-image/cdn
bash
yarn add @responsive-image/cdn
bash
pnpm add @responsive-image/cdn

You need to specify the cloudName in your configuration, which can vary across the supported frameworks:

js
// config/addons.js
module.exports = {
  '@responsive-image/ember': {
    cloudinary: {
      cloudName: 'my-org',
    },
  },
};

Usage

IMPORTANT

Please make sure you have read the section on remote images first.

Use the cloudinary provider function passing the reference to the image on the CDN and optional transformations, and pass the return value to the image component:

gjs
import { ResponsiveImage } from '@responsive-image/ember';
import { cloudinaryProvider } from '@responsive-image/cdn';

<template>
  <ResponsiveImage @src={{cloudinaryProvider 'path/to/uploaded/image.jpg'}} />
</template>
hbs
<ResponsiveImage
  @src={{responsive-image-cloudinary-provider 'path/to/uploaded/image.jpg'}}
/>

Transformations

Besides the transformations that the addon itself implicitly adds (related to resizing images) you can add your own Cloudinary transformations by using the transformations parameter:

gjs
import { ResponsiveImage } from '@responsive-image/ember';
import { cloudinaryProvider } from '@responsive-image/cdn';

<template>
  <ResponsiveImage
    @src={{cloudinaryProvider
      'path/to/uploaded/image.jpg'
      transformations=(hash co='rgb:20a020' e='colorize:50')
    }}
  />
</template>
hbs
<ResponsiveImage
  @src={{responsive-image-cloudinary-provider
    'path/to/uploaded/image.jpg'
    transformations=(hash co='rgb:20a020' e='colorize:50')
  }}
/>

It accepts an object of transformations, or an array of objects for chained transformations.

Quality

Use the quality parameter to pass a custom quality setting instead of the default auto:

gjs
import { ResponsiveImage } from '@responsive-image/ember';
import { cloudinaryProvider } from '@responsive-image/cdn';

<template>
  <ResponsiveImage
    @src={{cloudinaryProvider
      'path/to/uploaded/image.jpg'
      quality=50
    }}
  />
</template>
hbs
<ResponsiveImage
  @src={{responsive-image-cloudinary-provider
    'path/to/uploaded/image.jpg'
    quality=50
  }}
/>

Image formats

By default, all supported image formats (PNG, JPEG, WEBP, AVIF) are referenced in the generated <source> tags. You can tweak that using the formats argument:

gjs
import { ResponsiveImage } from '@responsive-image/ember';
import { cloudinaryProvider } from '@responsive-image/cdn';

<template>
  <ResponsiveImage
    @src={{cloudinaryProvider
      'path/to/uploaded/image.jpg'
      formats=(array 'webp' 'avif')
    }}
  />
</template>
hbs
<ResponsiveImage
  @src={{responsive-image-cloudinary-provider
    'path/to/uploaded/image.jpg'
    formats=(array 'webp' 'avif')
  }}
/>

Remote source

The provider supports Cloudinary's fetch mode to automatically fetch images from a remote source and deliver them (with optional custom transformations) through Cloudinary's CDN. Simply pass a fully qualified http(s) URL:

gjs
import { ResponsiveImage } from '@responsive-image/ember';
import { cloudinaryProvider } from '@responsive-image/cdn';

<template>
  <ResponsiveImage
    @src={{cloudinaryProvider
      'https://upload.wikimedia.org/wikipedia/commons/1/13/Benedict_Cumberbatch_2011.png'
    }}
  />
</template>
hbs
<ResponsiveImage
  @src={{responsive-image-cloudinary-provider
    'https://upload.wikimedia.org/wikipedia/commons/1/13/Benedict_Cumberbatch_2011.png'
  }}
/>

Made with ❤︎ for OSS - Support 🇺🇦