Next.js

The @freeplaceholder/next package provides type-safe <Placeholder> and <Avatar> components built on next/image.

Installation

bash
npm install https://github.com/freeplaceholder/next

Configuration

Add the hostname to your next.config.ts:

ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  images: {
    remotePatterns: [
      { protocol: "https", hostname: "freeplaceholder.com" },
    ],
  },
};

export default nextConfig;

Placeholder Component

Uses next/image under the hood for automatic optimization:

tsx
import { Placeholder } from "@freeplaceholder/next";

export default function Page() {
  return (
    <Placeholder
      width={800}
      height={400}
      text="Hero Banner"
      format="webp"
      bg="3b82f6"
      textColor="ffffff"
      fontWeight="bold"
      rounded="lg"
    />
  );
}

Placeholder Props

All props from the React package are supported, plus all next/image props (priority, placeholder, loading, etc.).

PropTypeDescription
widthnumberImage width in px (required)
heightnumberImage height in px (required)
formatImageFormatOutput format: svg, png, jpg, webp
bgstringBackground hex color
gradientGradientDirectionto-t, to-tr, to-r, to-br, to-b, to-bl, to-l, to-tl, radial
fromstringGradient start color — hex without #
viastringGradient middle color — hex without #
tostringGradient end color — hex without #
textColorstringText hex color
textstringCustom text overlay
textSizenumberFont size in px
textAlignTextAlignleft, center, right
textTransformTextTransformuppercase, lowercase, capitalize, none
textDecorationTextDecorationunderline, overline, line-through, none
letterSpacing`LetterSpacing \string`Letter spacing
fontWeightFontWeightFont weight
opacitynumber0–100
grayscalebooleanGrayscale filter
blurnumberGaussian blur 0–100 px
brightnessnumber0–200
contrastnumber0–200
hueRotatenumber0–360 degrees
invertbooleanInvert colors
saturatenumber0–200
sepiabooleanSepia tone
bordernumberBorder width in px
borderColorstringBorder hex color
borderStyleBorderStyleBorder style
rounded`Rounded \number`Border radius
lazybooleanEnable lazy loading with blur placeholder (default: true)

Avatar Component

tsx
import { Avatar } from "@freeplaceholder/next";

export default function UserCard({ user }) {
  return (
    <Avatar
      name={user.name}
      size={64}
      format="png"
      fontWeight="bold"
      grayscale
    />
  );
}

Avatar Props

All props from the React Avatar, plus all next/image props.

PropTypeDescription
namestringName to derive initials from (required)
sizenumberSquare dimensions in px (default: 128)
formatImageFormatOutput format
bgstringBackground hex color
gradientGradientDirectionto-t, to-tr, to-r, to-br, to-b, to-bl, to-l, to-tl, radial
fromstringGradient start color — hex without #
viastringGradient middle color — hex without #
tostringGradient end color — hex without #
textColorstringText hex color
textDecorationTextDecorationunderline, overline, line-through, none
letterSpacing`LetterSpacing \string`Letter spacing
fontWeightFontWeightFont weight
opacitynumber0–100
blurnumberGaussian blur 0–100 px
brightnessnumber0–200
contrastnumber0–200
hueRotatenumber0–360 degrees
invertbooleanInvert colors
saturatenumber0–200
sepiabooleanSepia tone
grayscalebooleanGrayscale filter
bordernumberBorder width in px
borderColorstringBorder hex color
borderStyleBorderStyleBorder style
rounded`Rounded \number`Border radius
lazybooleanEnable lazy loading with blur placeholder (default: true)

URL Helpers

tsx
import { avatarUrl, placeholderUrl, snippetUrl } from "@freeplaceholder/next";

const src = placeholderUrl({ width: 1920, height: 1080, format: "webp" });
const avatar = avatarUrl({ name: "Alice", size: 96 });
const og = snippetUrl({ title: "Docs", format: "png" });

App Router & Server Components

The components are marked "use client" so they work in both Server and Client components. For server-only usage, use the URL helpers directly:

tsx
import { placeholderUrl } from "@freeplaceholder/next";

export default function ServerPage() {
  return <img src={placeholderUrl({ width: 600, height: 400 })} alt="Placeholder" />;
}

Overriding Base URL

Add a custom base URL in your app configuration:

tsx
import { configure } from "@freeplaceholder/next";

configure({ baseUrl: "https://my-custom-instance.com" });