For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Dashboard
GuidesIntegrationsAPI ReferencesRelease notes
GuidesIntegrationsAPI ReferencesRelease notes
    • All integrations
  • Receiving files
    • Framework integrations
    • JavaScript File Uploader
    • React File Uploader
    • Angular File Uploader
    • Vue File Uploader
    • Svelte File Uploader
    • Next.js File Uploader
    • iOS
    • Android
    • CKEditor
    • TinyMCE
    • Redactor
    • Webflow
    • WordPress
    • Contentful CMS
    • JotForm
    • Marketo
  • Managing files
    • JavaScript SDK
    • PHP SDK
    • Python SDK
    • Ruby SDK
    • Rails SDK
    • Java SDK
    • Golang SDK
    • Rust SDK
    • Swift SDK
    • Kotlin SDK
    • Zapier
    • Make
    • Integrately
    • CLI
  • Delivering files
    • Adaptive image component
    • Next.js image loader
    • NuxtImage
  • From community
    • Shopify
    • Shopify (Debut theme)
    • WooCommerce
    • PHP Transformation URLs generation
    • Laravel Flysystem driver
    • Unpic Universal CDN URL translator
    • C# SDK
    • Erlang SDK
    • Elixir SDK
    • Flutter SDK
Dashboard
LogoLogo
On this page
  • Features
  • Installation
  • Configuration
  • Usage
  • Full documentation
Delivering files

Next.js Image Loader and Component

Was this page helpful?
Previous

Shopify integration

Next
Built with

Optimize images with Uploadcare on the fly by using the UploadcareImage component or the uploadcareLoader custom image loader for Next.js.

The built-in Next.js Image component does a great job in optimizing images but the number of optimizations is limited. It allows setting a custom image loader to process images externally. This is where the @uploadcare/nextjs-loader package comes in handy.

GitHub →

Here is a demo app and its source code.

Features

  • Optimize image characteristics (quality, resolution, format, and others) with an extended list of Uploadcare image processing operations.
  • Load the optimized images through Uploadcare CDN.

Installation

yarn add @uploadcare/nextjs-loader

Configuration

Get your public key from the Dashboard and add it to your environment variables through .env file or your hosting UI.

1# .env
2NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY="YOUR_PUBLIC_KEY"

If you’re using a proxy, provide your application’s base URL (also whitelisted), which is required to process local images properly.

1# .env
2NEXT_PUBLIC_UPLOADCARE_APP_BASE_URL="https://your-domain.com/"

Image transformation settings example:

1# .env
2NEXT_PUBLIC_UPLOADCARE_TRANSFORMATION_PARAMETERS="quality/lightest, stretch/off, progressive/yes"

The default image transformation parameters are stretch/off, progressive/yes.

Find additional settings, such as custom CDN domain, and custom proxy domain, in the developer documentation on Github.

Usage

Allow custom image loaders through next.config.js:

1// next.config.js
2module.exports = {
3 images: {
4 loader: "custom"
5 }
6}

The easiest and the most straightforward way of utilizing the power of Uploadcare is to use the UploadcareImage component for all images on your site the same way as the built-in Image component.

1import UploadcareImage from '@uploadcare/nextjs-loader';
2
3<UploadcareImage
4 alt="A test image"
5 src="https://your-domain/image.jpg"
6 width="400"
7 height="300"
8/>

If you still need to use the built-in Image component with the uploadcareLoader:

1import Image from 'next/image';
2import { uploadcareLoader } from '@uploadcare/nextjs-loader';
3
4<Image
5 alt="A test image"
6 src="https://your-domain/image.jpg"
7 width="400"
8 height="300"
9 loader={uploadcareLoader}
10/>

Note that if you pass a local image URL, the loader returns it AS IS if the app is run in the development mode or if the NEXT_PUBLIC_UPLOADCARE_APP_BASE_URL is not set.

Full documentation

Read the full documentation on GitHub.