This provides some shortcodes and filters for generating Cloudinary URLs.
Since the shortcodes this plugin provides are pretty generically named, it’s recommended that you namespace them:
conf.namespace('cl_', () => {
conf.addPlugin(cloudinary)
})
Now you have access to the shortcodes and filters that this plugin provides!
This plugin will try hard to extract public IDs and other information from Cloudinary URLs or segments of those URLs, but it will choke if you give it a Cloudinary URL that already has transforms in it.
The plugin accepts several configuration options.
name
- This is the cloud name for your Cloudinary account.
You must either pass a value here, or set the CLOUDINARY_URL
environment variable.
coerce
- The plugin with attempt to pluck out valid public asset IDs from whatever you provide it with–
i.e. full URLs, versioned URLs, etc.
If you don’t want this behavior, you can set coerce
to false
.
transforms
- optional
This is a set of transforms that will be applied to all images generated by the plugin.
It assumes an array in the manner of the transformation
argument on the node SDK.
(The node SDK powers most of what this plugin does.)
defaults
- optional
Adjust the defaults for various settings in the plugin.
width
- optional The fallback width used for an image if the plugin isn’t given one.
Defaults internally to 768
if no value is given.When you upload a file to Cloudinary, it is given (either explicitly or automatically) a public ID, which is how it can be identified by the API. A full discussion of public IDs is obviously beyond the scope of this document, so you are encouraged to read Cloudinary’s documentation on public IDs.
The (generally) first argument passed to a shortcode or filter in this plugin is the public ID.
Frequently this looks like a filename, i.e. image.jpg
but depending on how your images were uploaded to Cloudinary it may look different.
This plugin does not actually use the API to retrieve an asset record and generate a URL–if it did, you’d swamp Cloudinary with API requests on every build.
It’s mostly just concatenating strings in the appropriate format to use the Transformation URL API.
In many cases, image.jpg
is not actually the public ID of your asset:
The public ID is image
and the .jpg
extension just tells the URL API to serve that asset as a JPEG.
In most cases, you can use a URL for your asset and it will “just work,” but if things go sideways it can be helpful to know what’s going on behind the scenes. If you feel lik you’ve encountered a bug in this plugin, please file a bug report.