Generate Open Graph Images dynamically from HTML/CSS without a browser in SvelteKit
The SvelteKit Open Graph Image Generation is a library that allows users to dynamically generate Open Graph images from an HTML+CSS template or Svelte component. It utilizes fast and efficient conversion from HTML > SVG > PNG and is based on Satori. This library does not require a headless browser.
Please note that the documentation for this library is currently unmaintained, as the development focus is on compatibility with cloudflare, vercel, and vercel edge. The library is not recommended for production use until January 1, 2024.
To use the SvelteKit Open Graph Image Generation library with Cloudflare Pages or Workers, you need to provide a url polyfill by installing it as a devDependency. Create a file at /src/routes/og/+server.ts
. Alternatively, you can use JavaScript by removing the types from the provided example. Run npm dev
and visit localhost:5173/og
to view the generated PNG. Please note that hot module reloading does not work with server routes, so a hard refresh of the route is needed to see changes in the HTML or CSS.
The SvelteKit Open Graph Image Generation library allows users to dynamically generate Open Graph images from HTML+CSS templates or Svelte components. It offers fast and efficient conversion from HTML > SVG > PNG and does not require a headless browser. Although the documentation is currently unmaintained and not recommended for production use until January 1, 2024, the library provides key features such as support for Cloudflare Pages or Workers and the ability to generate customized PNG images for Open Graph.