Back in April, Cloudinary made available on npm an alpha version of its components library for Svelte, a release that’s a wonderful addition to Cloudinary’s suite of client-side SDKs: React, Vue, and Angular. Those three front-end SDKs offer simple yet comprehensive optimization, transformation, and delivery capabilities for images and videos—features that you can tailor to automatically apply the best-fitting formats for all devices and browsers.
The Svelte SDK offers all those capabilities to Svelte developers through two robust components, Images and Videos.
The Image Component
With the Image component, you can display and transform images stored on Cloudinary, for example, by having Cloudinary generate an HTML <img>
element whose source has been cropped as a circle and centered on someone’s face (see the photo below).
If you do not specify any image format, Cloudinary automatically applies the most suitable one for the browser. Here’s a code example:
<Image cloud_name="demo" public_id="woman" transformation="{{ width: 400, height: 400, gravity: 'face', radius: 'max', crop: 'crop' }}" />
The generated HTML <img>
element looks like this:
The Video Component
Similarly, the Video component enables you to display and transform videos stored on Cloudinary. For example, in automatically adding a poster image for a video, the Video component generates an HTML <video>
element for a source that has been rotated by 20 degrees. If you don’t specify a video format, the component automatically adds fallback sources, as in this example:
Here’s the generated HTML <video>
element:
<video controls="true" muted="true" poster="http://res.cloudinary.com/demo/video/upload/a_20/dog.jpg" > <source src="http://res.cloudinary.com/demo/video/upload/a_20/dog.webm" type="video/webm" /> <source src="http://res.cloudinary.com/demo/video/upload/a_20/dog.mp4" type="video/mp4" /> <source src="http://res.cloudinary.com/demo/video/upload/a_20/dog.ogv" type="video/ogg" /> </video>
Upcoming Enhancements
Keep in mind that, even though the Svelte SDK components are fully functional, this is an alpha version only. That’s because our roadmap for the future encompasses major improvements to our core JavaScript library, which will affect all the client SDKs that rely on that library.
Here are the main upcoming enhancements:
- A lighter modular bundle for importing used modules only.
- New actions-based transformation capabilities for defining media transformations in a simpler manner.
- An advanced Image component with built-in lazy loading and placeholder capabilities along with support for accessibility.
If you’re new to Cloudinary, to get started, just sign up for a free account, and do check out the new Svelte SDK on npm and its code repository on GitHub.