Programmable Media

Deliver images with the Next.js Image component (video tutorial)

Last updated: Dec-11-2024

Overview

Learn how to deliver Cloudinary images in your Next.js application using the Next.js Image component. Add Cloudinary URLs to the list of allowed domains for the Image component and use the built-in Next.js Cloudinary loader to take advantage of more Cloudinary features.

Note
The instructions to serve images directly from Cloudinary work only for Next.js 12 and below due to Next.js 13 deprecating global loaders. Instead, try the CldImage component of the Next Cloudinary library.

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.

The Next.js Image component

Jump to this spot in the video  0:05 There are many components and tools that Next.js provides out of the box, including the Next.js Image component, which implements its own optimization capabilities. You can use the Image component together with Cloudinary delivery URLs to take advantage of both technologies.

Replace existing img tags with Next.js Image components

Jump to this spot in the video  0:21 Import the Image component from next/image and swap your existing img tags for Image components.

Add the Cloudinary domain to the allowed list

Jump to this spot in the video  0:29 To allow images to originate from Cloudinary, add the Cloudinary domain to the allowed list. In next.config.js, add an images property containing a domains property. The domains property is an array of domains where you are serving your images from, for example, res.cloudinary.com.
See example code.

Serve images directly from Cloudinary

Jump to this spot in the video  1:15 Only for Next.js 12 and below. To allow images to be served directly from Cloudinary, use the loaders functionality. In next.config.js,replace the domains property with a loader key that has a value of cloudinary. Add a path key, and set the value to the first part of your delivery URLs, for example, https://res.cloudinary.com/my_cloud/image/upload. Then, remove that part of the address from each of the image URLs in your code.
See example code (this doesn't use global loaders so can be used with Next.js 13).

Keep learning

Related topics
  • Watch more Dev Hints videos on the Cloudinary YouTube channel.
  • Try out the community-developed Next Cloudinary library that provides components to enable you to upload and apply popular Cloudinary transformation and optimization features to your media when building Next.js applications.

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

Embedding Videos in Next.js
Use the Cloudinary Video Player to embed videos using Next.js
AI Generative Fill using Next.js
Extend images using generative AI in a Next.js app
Create Social Media Cards in Next.js
Dynamically create social media image cards using Next.js

 

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: