Generate 1200x630 Open Graph images from an HTML template using Puppeteer.
git clone https://github.com/fullmetalbrackets/html-to-og.git
cd html-to-og
npm iEdit the template HTML file at template/og.html. (Or drop in your own, as long as you name it og.html so the script can pick it up.)
Any other necessary files like stylesheets, fonts and images go in the template/ directory as well.
When ready to generate an image, run:
npm startGenerated images are saved to output/ as og-card1.png, og-card2.png, etc. Each run creates a new numbered file without overwriting previous versions.
To clear out the output/ directory of all PNGs, run:
npm run cleanThis is the OG image generated for my own site based on template/og.html:

The script uses Puppeteer to:
- Load your HTML template in a headless browser
- Set viewport to 1200x630 (Open Graph standard size)
- Capture a screenshot of the
.og-cardelement - Save the PNG to the output directory
- Node.js >= 18.0.0
.
├── template/ # place any images, fonts or css files here
│ └── og.html # Edit or replace this template
├── output/ # Generated images appear here
└── html-to-og.mjs # Script to generate images from og.html file