manifold/og-image/api/_lib/chromium.ts
Austin Chen ed37d93868
Dynamically generate Opengraph images for each market (#21)
* Start customizing opengraph image

* Fix cover image size to 1200x630

* Design a text-based, dynamic preview card

* Load designed html into template.ts

Remove twemoji for now too

* Take in params to configure Manifold card

* Switch back to hardcoded png for default case
2022-01-10 00:50:31 -05:00

27 lines
643 B
TypeScript

import core from "puppeteer-core";
import { getOptions } from "./options";
import { FileType } from "./types";
let _page: core.Page | null;
async function getPage(isDev: boolean) {
if (_page) {
return _page;
}
const options = await getOptions(isDev);
const browser = await core.launch(options);
_page = await browser.newPage();
return _page;
}
export async function getScreenshot(
html: string,
type: FileType,
isDev: boolean
) {
const page = await getPage(isDev);
await page.setViewport({ width: 1200, height: 630 });
await page.setContent(html);
const file = await page.screenshot({ type });
return file;
}