The Open Graph protocol allows for embedding links into posts on social media with rich information about the target, including an image. The OpenGraph standard is used by Linked In, Facebook and others.
NextJS allows for the management fo the Open Graph image by convention in naming the metadata files. In particular, there are two file names that would make NextJS generate the OpenGraph images:
opengraph-image
twitter-image
The supported extensions for both files are: .jpg, .jpeg, .png, .gif. The images are placed in the directory corresponding to the relative path of the page. In this particular case we place one image in the src\app directory:
As a check, before placing the image, the metadata for the home page looks like:
After adding the image, we get a warning from the build tool:
Generating static pages (0/10) [ ] ⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
The generated metadata in the header now contains the link to the OpenGraph Image:
It is worth noticing that NextJS uses the same image for both the OpenGraph as well as the Twitter Card tags.
There is plentiful, albeit sometimes contradictory, information about the required dimensions for the metadata images. Here are a few links to detailed articles and analysis: