A lightweight, self-hosted HTML-to-PNG screenshot API built with Node.js, Express, Playwright, and Chromium.
Email Screenshot API accepts HTML through a simple REST API, renders it using headless Chromium, and returns a full-page PNG screenshot.
It is designed primarily for email automation, but can also be used for invoices, reports, notifications, previews, documents, and other HTML-based content that needs to be converted into an image.
The API is Docker-ready and can be deployed on your own VPS or infrastructure.
- 📧 Convert HTML emails into PNG screenshots
- 🖼️ Convert any HTML content into PNG
- 📄 Full-page screenshots
- 🌐 Supports external images, fonts, CSS, and web resources
- 🎭 Headless Chromium rendering with Playwright
- ⚡ Simple REST API
- 📦 JSON request body
- 🖼️ PNG response
- ❤️ Health-check endpoint
- 🐳 Docker-ready
- 🔒 Self-hosted and suitable for private infrastructure
- 🔄 Works with n8n and other automation platforms
- 🚀 Easy to deploy on a VPS
- 🧩 No browser installation required on the host when using Docker
HTML Email
│
▼
POST /screenshot
│
▼
Express API
│
▼
Playwright
│
▼
Headless Chromium
│
▼
Rendered HTML
│
▼
PNG Screenshot
A typical email automation workflow can look like:
IMAP Email
│
▼
Extract Email HTML
│
▼
Email Screenshot API
│
▼
PNG Screenshot
│
▼
WhatsApp / Email / Storage / Notification
The easiest way to run Email Screenshot API is with Docker.
You need:
- Docker
- Git
Node.js is only required if you want to run the application directly without Docker.
Clone the repository:
git clone https://github.com/icodedigita/EmailScreenshotAPI.gitEnter the directory:
cd EmailScreenshotAPIBuild the Docker image:
docker build -t email-screenshot-api .Run the container:
docker run -d \
--name email-screenshot-api \
-p 3000:3000 \
email-screenshot-apiThe API will now be available at:
http://localhost:3000
Check whether the API is running:
curl http://localhost:3000/healthExpected response:
{
"status": "ok"
}Send HTML to the /screenshot endpoint.
curl -X POST http://localhost:3000/screenshot \
-H "Content-Type: application/json" \
--data '{"html":"<html><body><h1>Hello World</h1><p>This is a screenshot.</p></body></html>"}' \
--output screenshot.pngThe generated image will be saved as:
screenshot.png
Checks whether Email Screenshot API is running.
{
"status": "ok"
}Converts supplied HTML into a PNG screenshot.
Content-Type: application/json
{
"html": "<html>...</html>"
}{
"html": "<html><body><h1>Invoice</h1><p>Thank you for your purchase.</p></body></html>"
}The endpoint returns:
Content-Type: image/png
The browser viewport is configured as:
Width: 1200px
Height: 800px
Device Scale Factor: 1
The screenshot is generated with:
fullPage: true
This means the generated PNG contains the complete rendered page rather than only the initial viewport.
const response = await fetch(
"http://localhost:3000/screenshot",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
html: `
<!DOCTYPE html>
<html>
<body>
<h1>Hello from Email Screenshot API</h1>
<p>This HTML will be converted into a PNG.</p>
</body>
</html>
`
})
}
);
if (!response.ok) {
throw new Error(
`Screenshot API returned ${response.status}`
);
}
const imageBuffer = await response.arrayBuffer();import requests
html = """
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
}
</style>
</head>
<body>
<h1>Hello from Python</h1>
<p>This HTML will be rendered as a PNG.</p>
</body>
</html>
"""
response = requests.post(
"http://localhost:3000/screenshot",
json={"html": html}
)
response.raise_for_status()
with open("screenshot.png", "wb") as file:
file.write(response.content)
print("Screenshot saved as screenshot.png")Email Screenshot API works directly with n8n using the HTTP Request node.
A basic workflow:
HTML
│
▼
HTTP Request
│
▼
Email Screenshot API
│
▼
PNG Binary
│
▼
Next Automation Step
For email automation:
IMAP Email
│
▼
Extract HTML
│
▼
HTTP Request
│
▼
Email Screenshot API
│
▼
PNG
│
▼
WhatsApp / Email / Storage
Configure the HTTP Request node:
POST
https://your-domain.com/screenshot
JSON
{
"html": "={{ $json.html }}"
}Configure the response as a file/binary response.
The generated PNG can then be passed to other n8n nodes.
A ready-to-import example is included:
examples/n8n/html-to-screenshot.json
Additional n8n documentation is available here:
Email Screenshot API was designed with email automation in mind.
A typical workflow:
┌─────────────────┐
│ IMAP Server │
└────────┬────────┘
│
▼
┌─────────────────┐
│ n8n / IMAP │
│ Email Trigger │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Extract Email │
│ HTML │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Email Screenshot│
│ API │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Playwright │
│ Chromium │
└────────┬────────┘
│
▼
┌─────────────────┐
│ PNG Image │
└────────┬────────┘
│
▼
WhatsApp / Email /
Storage / Notification
This can be useful for:
- Email archiving
- Visual email processing
- Email notifications
- WhatsApp email previews
- Automated reporting
- Monitoring workflows
- Visual records of transactional emails
Because the HTML is rendered using Chromium, the page can use resources that are accessible from the screenshot server.
Supported resources can include:
- Images
- Web fonts
- CSS
- External stylesheets
- Other web resources
Example:
<img src="https://example.com/logo.png">The screenshot server must be able to access the external resource.
Email Screenshot API uses the official Playwright Docker image:
FROM mcr.microsoft.com/playwright:v1.63.0-noble
WORKDIR /app
COPY package*.json ./
RUN npm install --omit=dev
COPY server.js .
ENV PORT=3000
EXPOSE 3000
CMD ["node", "server.js"]The Playwright image includes Chromium and the required Linux dependencies.
This means you do not need to manually install Chromium on the host machine.
Email Screenshot API can be deployed to a VPS using Coolify.
In Coolify:
New Resource
↓
Application
↓
Git Repository
Connect your GitHub repository.
Select:
Dockerfile
Coolify will build the application using the repository's Dockerfile.
Set the application port to:
3000
Assign your domain, for example:
https://screenshot.example.com
Your screenshot endpoint will then be:
https://screenshot.example.com/screenshot
Health check:
https://screenshot.example.com/health
This project provides a lightweight rendering API.
If you expose the API publicly, consider adding authentication and additional restrictions.
Potential improvements include:
- API keys
- Bearer-token authentication
- Rate limiting
- Request size limits
- IP restrictions
- Reverse-proxy authentication
- Request logging
- Concurrent rendering limits
- Timeouts
- Resource restrictions
For private automation infrastructure, placing the service behind a private network or authenticated reverse proxy is recommended.
The API renders user-provided HTML inside Chromium.
If the endpoint is exposed to untrusted users, submitted HTML should be treated as potentially unsafe input.
A production deployment should consider additional isolation and restrictions around:
- External network requests
- JavaScript execution
- Resource consumption
- Large HTML documents
- Concurrent browser pages
- Potentially expensive pages
For trusted internal automation, such as an n8n server sending controlled HTML to the API, the risk profile is different from exposing the endpoint as a public anonymous API.
The application currently supports:
Default:
3000
Example:
docker run -d \
--name email-screenshot-api \
-p 3000:3000 \
-e PORT=3000 \
email-screenshot-apiEmailScreenshotAPI/
│
├── Dockerfile
├── package.json
├── server.js
├── README.md
│
├── docs/
│ └── n8n.md
│
└── examples/
└── n8n/
├── README.md
└── html-to-screenshot.json
Contains the Express API and Playwright screenshot functionality.
Defines the Docker image using the official Playwright image with Chromium.
Defines the Node.js application and dependencies.
Detailed documentation for using Email Screenshot API with n8n.
Contains ready-to-import n8n workflow examples.
| Technology | Purpose |
|---|---|
| Node.js | Runtime |
| Express | HTTP API |
| Playwright | Browser automation |
| Chromium | HTML rendering |
| Docker | Containerization |
| n8n | Optional automation integration |
Only Docker is required.
You will need:
- Node.js
- npm
- Playwright
- Chromium
Install dependencies:
npm installInstall Playwright Chromium:
npx playwright install chromiumStart the server:
npm startThe API will be available at:
http://localhost:3000
Check the health endpoint:
curl http://localhost:3000/healthTest screenshot generation:
curl -X POST http://localhost:3000/screenshot \
-H "Content-Type: application/json" \
--data '{"html":"<h1>Hello World</h1>"}' \
--output screenshot.pngOpen:
screenshot.png
Potential future improvements:
- API key authentication
- Rate limiting
- Configurable viewport size
- Configurable device scale factor
- JPEG/WebP output
- PDF generation
- Custom screenshot dimensions
- Custom user-agent support
- Custom HTTP headers
- Screenshot quality settings
- Request timeout configuration
- Browser/page concurrency controls
- Queue-based rendering
- Optional JavaScript execution controls
- Docker Compose example
- Additional n8n workflow examples
Contributions are welcome.
If you find a bug or have an idea for an improvement:
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Test the application.
- Submit a pull request.
For larger changes, opening an issue first is recommended so the approach can be discussed.
If Email Screenshot API is useful to you, consider giving the repository a ⭐ on GitHub.
It helps other developers discover the project and supports continued development.
If you find a bug or have an idea for an improvement, feel free to open an issue or submit a pull request.
This project is released under the license included in the repository's LICENSE file.
See LICENSE for the complete license terms.
HTML emails can contain complex layouts, CSS, images, fonts, tables, and other browser-rendered content.
Getting a reliable image representation of that HTML usually requires a browser engine.
Email Screenshot API provides a simple interface:
HTML Email
↓
REST API
↓
Playwright
↓
Chromium
↓
PNG
Your application or automation platform does not need to manage browser automation itself.
Send HTML to the API and receive a ready-to-use screenshot.
Email Screenshot API can be integrated into almost any workflow:
Email / HTML Template / Application
│
▼
Email Screenshot API
│
▼
PNG
│
┌─────────┼─────────┐
▼ ▼ ▼
WhatsApp Email Storage
It can be self-hosted on your own infrastructure and used wherever you need reliable HTML-to-image rendering.
© 2026 ICODEDIGITA LLC.