Image

A next/image wrapper optimized for Stack0 CDN with built-in image transformations. Uses a custom loader to bypass Next.js image optimization in favor of CDN-level processing.

Demo

Default

Mountain landscape

With WebP transform

Mountain landscape

With blur effect

Mountain landscape

Why Use This Component?

When using Stack0 CDN, image optimization happens at the CDN level, not in your Next.js application. This component:

  • Bypasses Next.js image optimization - Prevents double processing
  • Uses Stack0 CDN transforms - Width, height, format, quality via URL params
  • Maintains all next/image features - Lazy loading, blur placeholder, responsive sizing
  • Type-safe transforms - Full TypeScript support for CDN options

Basic Usage

basic-example.tsx
import { Image } from '@stack0/elements'
export function Example() {
return (
<Image
src="https://cdn.stack0.dev/your-image.jpg"
alt="Description"
width={800}
height={600}
/>
)
}

With CDN Transforms

transforms-example.tsx
import { Image } from '@stack0/elements'
export function OptimizedImage() {
return (
<Image
src="https://cdn.stack0.dev/your-image.jpg"
alt="Optimized image"
width={800}
height={600}
transforms={{
format: "webp", // Convert to WebP
quality: 85, // 85% quality
fit: "cover", // Cover fit mode
}}
/>
)
}

Props

PropTypeDescription
srcstringImage source URL (required)
altstringAlt text for accessibility (required)
widthnumberImage width in pixels (required unless fill)
heightnumberImage height in pixels (required unless fill)
transformsImageTransformOptionsStack0 CDN transformation options
loaderImageLoaderCustom loader (overrides default Stack0 loader)
...propsNextImagePropsAll other next/image props are supported

Transform Options

OptionTypeDescription
format"webp" | "avif" | "jpeg" | "png" | "gif"Output format
qualitynumber (1-100)Output quality percentage
fit"cover" | "contain" | "fill" | "inside" | "outside"Resize fit mode
blurnumber (0.3-1000)Blur amount
sharpennumber (0-10)Sharpen amount
rotate0 | 90 | 180 | 270Rotation angle
flipH / flipVbooleanFlip horizontally / vertically
backgroundstring (hex without #)Background color for transparent images

Responsive Images

responsive-example.tsx
import { Image } from '@stack0/elements'
export function ResponsiveImage() {
return (
<Image
src="https://cdn.stack0.dev/hero.jpg"
alt="Hero image"
fill
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
transforms={{ format: "webp", quality: 80 }}
className="object-cover"
/>
)
}

Custom Loader

For advanced use cases, you can provide your own loader function:

custom-loader.tsx
import { Image } from '@stack0/elements'
// Custom loader for a different CDN
const myLoader = ({ src, width, quality }) => {
return `https://my-cdn.com/${src}?w=${width}&q=${quality || 75}`
}
export function CustomLoaderExample() {
return (
<Image
loader={myLoader}
src="images/photo.jpg"
alt="Custom loaded image"
width={800}
height={600}
/>
)
}

Using the Loader Utility

You can also use the createStack0Loader function directly:

loader-utility.tsx
import { createStack0Loader } from '@stack0/elements'
import NextImage from 'next/image'
const loader = createStack0Loader({
format: "webp",
quality: 85,
})
export function DirectLoaderExample() {
return (
<NextImage
loader={loader}
src="https://cdn.stack0.dev/image.jpg"
alt="Direct loader usage"
width={800}
height={600}
/>
)
}