<CldOgImage />
Basic Usage

Getting Started with CldOgImage

The CldOgImageComponent give you the ability to use the same CldImage API to easily generate Open Graph images (or social cards) inside of Next.js.

Using the Next.js 13 App Router? This component is only supported in the Pages directory. Try the getCldOgImageUrl helper inside of your metadata configuration.

Basic Usage

The basic required prop is src:

import { CldOgImage } from 'next-cloudinary';
 
<CldOgImage
  src="<Public ID>"
/>

Place the CldOgImage component anywhere outside of the Head component.

The CldOgImage component must be placed outside of the Next.js Head component as the Head component does not accept React components as children.

The resulting HTML will be applied to the Head of the document including all applicable open graph tags (opens in a new tab):

<meta property="og:image" content="https://res.cloudinary.com/colbycloud-next-cloudinary/image/upload/c_fill,w_2400,h_1254,g_center/c_scale,w_1200/f_jpg/q_auto/v1/images/galaxy" />
<meta property="og:image:secure_url" content="https://res.cloudinary.com/colbycloud-next-cloudinary/image/upload/c_fill,w_2400,h_1254,g_center/c_scale,w_1200/f_jpg/q_auto/v1/images/galaxy" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="627" />
<meta property="twitter:title" content=" " />
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:image" content="https://res.cloudinary.com/colbycloud-next-cloudinary/image/upload/c_fill,w_2400,h_1254,g_center/c_scale,w_1200/f_webp/q_auto/v1/images/galaxy" />

Turtle in the ocean

CldOgImage does not render an <img> tag, meaning it can't be visually embedded on a page. This example makes use of the <CldImage> tag to showcase what's possible.

Transformations

You can further take advantage of Cloudinary features like background removal and overlays by adding additional props.

The CldOgImage component uses the same API as CldImage, meaning you can use the same transformations and effects.

<CldOgImage
  src="<Public ID>"
  tint="100:0762a0"
  removeBackground
  opacity="40"
  overlays={[{
    text: {
      color: 'white',
      fontFamily: 'Source Sans Pro',
      fontSize: 200,
      fontWeight: 'bold',
      text: '<Text>'
    }
  }]}
  underlay="<Public ID>"
  alt="<Description>"
  twitterTitle="<Title>"
/>

Turtle in the ocean

CldOgImage does not render an <img> tag, meaning it can't be visually embedded on a page. This example makes use of the <CldImage> tag to showcase what's possible.

Watch & Learn

View on YouTube

Learn More about CldOgImage