Go to file
hazel c6d2e13901
bump version
2023-09-10 13:47:20 -05:00
lib/satori-html rework to use <style> tags, clean up 2023-09-10 13:38:46 -05:00
.eslintignore Initial commit 2023-08-02 02:07:49 -05:00
.eslintrc.cjs lint 2023-08-02 18:10:47 -05:00
.gitignore Initial commit 2023-08-02 02:07:49 -05:00
.prettierignore Initial commit 2023-08-02 02:07:49 -05:00
.prettierrc Initial commit 2023-08-02 02:07:49 -05:00
LICENSE Initial commit 2023-08-02 02:07:49 -05:00
README.md bump version 2023-09-10 13:47:20 -05:00
index.js rework to use <style> tags, clean up 2023-09-10 13:38:46 -05:00
package.json bump version 2023-09-10 13:47:20 -05:00
pnpm-lock.yaml rework to use <style> tags, clean up 2023-09-10 13:38:46 -05:00

README.md

@besties/html2png

A wrapper for satori and @resvg/resvg-wasm, adding support for using HTML strings rather than VDOM along with specifying classes for elements by inlining all CSS.

Usage

import html2png from '@besties/html2png'
import fs from 'node:fs'

const someFont = fs.readFileSync('./example.ttf')

fs.promises.writeFile(
	'test.png',
	await html2png(
		'<div class="main"><p>Hello world!</p></div>
		<style>
			.main {
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: #1b171f;
				color: #ffffff;
				width: 100%;
				height: 100%;
				font-size: 4rem;
			}
		</style>',
		{
			width: 400,
			height: 200,
			fonts: [
				{
					name: 'Example',
					data: someFont,
					weight: 400,
					style: 'normal'
				}
			]
		}
	)
)