Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bybetas/h2i
A simple HTML to Image API
https://github.com/bybetas/h2i
html puppeteer rendering
Last synced: 3 months ago
JSON representation
A simple HTML to Image API
- Host: GitHub
- URL: https://github.com/bybetas/h2i
- Owner: bybetas
- License: mit
- Created: 2024-08-26T16:07:17.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-30T12:08:41.000Z (3 months ago)
- Last Synced: 2024-09-30T14:07:52.303Z (3 months ago)
- Topics: html, puppeteer, rendering
- Language: JavaScript
- Homepage: https://hub.docker.com/r/bybetas/h2i
- Size: 54.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTML to Image API (H2I)
This API provides a service to convert HTML content or a URL into JPEG images using Playwright. It's designed to be simple, efficient, and deployable on platforms like Railway. Pre-built Docker images are available at `bybetas/h2i:latest`.
## Endpoints
### HTML to Image Conversion
- **URL**: `/convert`
- **Method**: `POST`
- **Description**: Converts provided HTML content, a URL, or a base64 HTML string into a JPEG image.
- **Headers**:
- `X-Render-Secret` (optional): The secret key for authentication if `H2I_RENDER_SECRET` is set
- **Body**:
- Content-Type: `application/json`
- Required field: Either `html` (string) - The HTML content to be converted, `url` (string) - The URL of the page to be converted, or `html64` (string) - The base64 encoded HTML content to be converted
- **Query Parameters**:
- `width` (optional): Desired width of the output image in pixels
- `height` (optional): Desired height of the output image in pixels
- **Response**:
- Content-Type: `image/jpeg`
- The JPEG image of the rendered HTML, URL, or base64 HTML string## Authentication
If the `H2I_RENDER_SECRET` environment variable is set, clients must provide the correct secret in the `X-Render-Secret` header when making requests to the `/convert` endpoint. If the secret is not set (empty string), the server will allow all requests without checking for a secret.
## Usage
### Basic Usage with HTML
To convert HTML to an image:
```http
POST /convert
Content-Type: application/json
X-Render-Secret: your_secret_here{
"html": "Hello, World!
"
}
```### Basic Usage with URL
To convert a URL to an image:
```http
POST /convert
Content-Type: application/json
X-Render-Secret: your_secret_here{
"url": "https://example.com"
}
```### Specifying Dimensions
To convert HTML or a URL to an image with specific dimensions:
```http
POST /convert?width=800&height=600
Content-Type: application/json
X-Render-Secret: your_secret_here{
"html": "Hello, World!
"
}
```Or for a URL:
```http
POST /convert?width=800&height=600
Content-Type: application/json
X-Render-Secret: your_secret_here{
"url": "https://example.com"
}
```## License
MIT License: You can do almost anything with this software, as long as you include the original license and copyright notice.