Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/diogoangelim/html-screenshots

Take screenshots from server side rendered html.
https://github.com/diogoangelim/html-screenshots

Last synced: 5 days ago
JSON representation

Take screenshots from server side rendered html.

Awesome Lists containing this project

README

        

# HTML Screenshots

This module generates a preview image from HTML content using Puppeteer. It allows the injection of custom CSS and JavaScript files, saves the generated image as a JPEG, and returns a base64 string representation of the image.
## Installation

Install HTML Screenshots with npm:

```bash
npm install html-screenshots
```


## Usage/Examples

```javascript
import icon from 'html-screenshots';

const basePath: '/path/to/save/image',

const htmlContent = `


Hello, World!


This is a test.



`;

const options = {
cssFiles: ['styles.css'],
jsFiles: ['script.js']
};

(async () => {
try {
await icon(basePath, htmlContent, options);
} catch (error) {
console.error('Error generating image:', error.message);
}
})();

```