Reputation: 414
I have started a Next.js project that needs to get image assets from two different sources:
<Image src="/logo.png" width={50} height={50} alt='Logo' layout="fixed"/>
<Image src="<transformations>/<version>/<public_id>.jpg" width={400} height={400} alt='Planning garden image'/>
When setting the images path in the next.config.js
file, images meant to load from the public file now point to Cloudinary.
The image loader path is set in the Next.js configuration file:
// next.config.js
module.exports = {
images: {
loader: 'cloudinary',
path: 'https://res.cloudinary.com/<cloud_name>/image/upload',
},
}
This means that the 1. above also uses relative URLs for the Image src and prepends it with the path in the config folder. This is incorrect for images stored in the public folder - which would be the default path if the configuration for Cloudinary were not set.
Can I have image paths coming from different sources depending on the context in which I'm using them. I don't want to put all the images on Cloudinary. I want 1 to still come from the public folder.
Upvotes: 1
Views: 2746
Reputation: 414
The key bit of information is: "Loaders can be defined per-image, or at the application level."
When the loader configuration is set at the application level so that cloud-based image optimisation can be used, to get local images working override their loader configuration.
As Jerry showed how to do in the comment: <Image loader={({src})=> src} src="/logo.png" layout="fill" />
Upvotes: 5