# Fumadocs (Framework Mode, Next.js): Takumi
URL: /docs/next/integrations/og/takumi
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/og/takumi.mdx

Integrate Takumi for framework agnostic and fast metadata image generation.

## Installation [#installation]

```npm
npm install takumi-js
```

`takumi-js` loads a native binding (`@takumi-rs/core`) on Node.js. Mark it as external to keep it out of the server bundle:

```ts title="next.config.ts"
import type { NextConfig } from 'next';

const config: NextConfig = {
  // [!code ++]
  serverExternalPackages: ['@takumi-rs/core'],
};
```

## Metadata Image [#metadata-image]

Add a function that returns the image URL of a page, and reference the image in the metadata of docs pages:

```ts tab="lib/source.ts"
// [!code ++:8]
export function getPageImageUrl(page: (typeof source)['$inferPage']) {
  const segments = [...page.slugs, 'image.webp'];

  return {
    segments,
    url: '/' + [page.locale, 'og', 'docs', ...segments].filter(Boolean).join('/'),
  };
}
```

```tsx tab="app/docs/[[...slug]]/page.tsx"
import { notFound } from 'next/navigation';
import { source, getPageImageUrl } from '@/lib/source';
import type { Metadata } from 'next';

export async function generateMetadata(props: PageProps<'/docs/[[...slug]]'>): Promise<Metadata> {
  const params = await props.params;
  const page = source.getPage(params.slug);
  if (!page) notFound();

  return {
    title: page.data.title,
    description: page.data.description,
    openGraph: {
      // [!code ++]
      images: getPageImageUrl(page).url,
    },
  };
}
```

> The image of `/docs/my-page` is at `/og/docs/my-page/image.webp`, since WebP images are smaller than PNG ones. To generate PNG, use `image.png` and `format: 'png'` instead.

Then create a route to generate the images:

```tsx title="app/og/docs/[...slug]/route.tsx"
import { getPageImageUrl, source } from '@/lib/source';
import { notFound } from 'next/navigation';
import { generateOGImage } from 'fumadocs-ui/og/takumi';

export const revalidate = false;

export async function GET(_req: Request, { params }: RouteContext<'/og/docs/[...slug]'>) {
  const { slug } = await params;
  const page = source.getPage(slug.slice(0, -1));
  if (!page) notFound();

  return generateOGImage({
    title: page.data.title,
    description: page.data.description,
    site: 'My App',
    format: 'webp',
  });
}

export function generateStaticParams() {
  return source.getPages().map((page) => ({
    lang: page.locale,
    slug: getPageImageUrl(page).segments,
  }));
}
```

> Takumi bundles the full-axis (100-900) [`Geist`](https://vercel.com/font) and `Geist Mono` fonts, so no font setup is needed.

See [Takumi's Documentation](https://takumi.kane.tw/docs) for advanced usage.

### Other Templates [#other-templates]

See [Takumi Templates](https://takumi.kane.tw/docs/templates) for the available templates.