This project automatically generates Open Graph images for blog posts based on their content. It creates custom images for social media sharing and caches them for improved performance.
-
Image Generation API
- The
/api/createblog
endpoint handles POST requests with blog post data. - It passes the data to the
/api/generate
endpoint to generate an image. - It uses the
canvas
library to create an image with the blog's title, description, and author. - If a custom image is provided, it's used as a background with an overlay gradient.
- The generated image is saved as a PNG file on vercel blob storage and the url is returned.
- The
/api/createblog
endpoint also creates a blog entry in the database.
- The
-
Metadata Generation
- The
generateMetadata
function fetches the blog data from the database. - If an Open Graph image URL is present, it returns metadata including the URL.
- The
-
Image Caching
- Generated images are saved on vercel blob storage, avoiding regeneration on subsequent requests.
-
Blog Post Display
- The blog post page displays the content along with the generated Open Graph image.
- Dynamic image generation based on blog post content
- Gradient overlays for background images
- Text wrapping for titles and descriptions
- Fallback to default styling if no custom image is provided
- Caching of generated images for improved performance
- Integration with Next.js metadata API for SEO optimization