Programmable Media

Configure Svelte Cloudinary (video tutorial)

Last updated: Sep-12-2024

Overview

Learn how to install and configure the Svelte Cloudinary community-developed library in your environment. This will enable you to utilize Cloudinary for uploading, managing, and displaying assets in your applications.

Video tutorial


View the code
You can find the code from this tutorial in GitHub.

Tutorial contents

This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

Introduction

Jump to this spot in the video  0:00 Svelte is a modern JavaScript framework designed for building web applications, with SvelteKit providing a convenient option for constructing full-stack applications. Svelte Cloudinary enables developers to manage and optimize the media files in their applications.

More about Svelte Cloudinary

Jump to this spot in the video  0:23 Svelte Cloudinary provides access to components for optimizing and modifying media files, and enabling client-side media uploads. Additionally, Cloudinary provides a Node.js SDK for server-side integration with Svelte applications, particularly useful for managing image uploads in scenarios like user forms. This video tutorial focuses on setting up and utilizing the Svelte SDK within an existing Svelte application.

Install and configure Svelte Cloudinary

Jump to this spot in the video  1:04 The first step is to install Svelte Cloudinary using npm install svelte-cloudinary. Once installed, set your environment variable for Cloudinary in your .env.local or .env file using the format: VITE_PUBLIC_CLOUDINARY_CLOUD_NAME="[Your Cloud Name]". Find your Cloud name on your Cloudinary Dashboard.

The CldImage component

Jump to this spot in the video  1:23 Now, you can start using Cloudinary. Let's focus on the CldImage component. Import it using import { CldImage } from "svelte-cloudinary", and in your app, instead of using the standard image tag, use CldImage. For the source, pass a public ID of the image. In this example, the public ID for a Cloudinary image is "demo/red-sneaker".

Setting width and height properties

Jump to this spot in the video  1:46 You also need to define the width and height properties to avoid layout shift. This setup ensures optimized images, with the image format tailored to the device, reducing file size significantly.

Image optimization

Jump to this spot in the video  1:50 Open the Network tab and refresh your page to check the format and size of your image, with and without the CldImage component. You'll notice that when you use CldImage, your images are smaller and use the format that's optimal for the requesting browser.

Use CldImage to display multiple images

Jump to this spot in the video  2:23 Use the following sample code to render multiple images with Svelte Cloudinary's CldImage component.

Remove background

Jump to this spot in the video  2:30 You can leverage different Cloudinary features with the CldImage component. For instance, using the remove background feature. (You'll need the background removal add-on for this feature).

Overlays

Jump to this spot in the video  2:45 Other features include overlays, such as adding text watermarks to images. Check the CldImage Configuration page for acceptable properties and values.

Keep learning

Related topics

If you like this, you might also like...

Transform and Optimize Images in Svelte
Transform and optimize images delivered in a Svelte app
Upload Assets in SvelteKit
Upload assets using the Upload widget in a SvelteKit App
Configure the JavaScript SDK in Svelte
Install and configure the Cloudinary JavaScript SDK using Svelte

 

Cloudinary Academy

 

Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.

 

✔️ Feedback sent!

Rate this page: