https://github.com/bartmika/htmltoimage-server
Selfhosted HTML to image service powered by Golang RPC server for your web-applications.
https://github.com/bartmika/htmltoimage-server
golang selfhost
Last synced: 14 days ago
JSON representation
Selfhosted HTML to image service powered by Golang RPC server for your web-applications.
- Host: GitHub
- URL: https://github.com/bartmika/htmltoimage-server
- Owner: bartmika
- License: isc
- Created: 2022-10-07T02:39:26.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-07T05:56:05.000Z (over 3 years ago)
- Last Synced: 2025-02-24T10:18:56.761Z (over 1 year ago)
- Topics: golang, selfhost
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTML to Image Server
Self-hosted HTML to image service powered by Golang RPC server for your web-applications.
## Installation
Create the `docker-compose.yml` file your directory.
```yaml
version: '3.8'
services:
app:
container_name: htmltoimage_server_app
image: bartmika/htmltoimage-server:latest
stdin_open: true
environment:
HTMLTOIMAGE_SERVER_IP: 0.0.0.0
HTMLTOIMAGE_SERVER_PORT: 8002
HTMLTOIMAGE_SERVER_CHROME_HEADLESS_WS_URL: ws://browserless:9090
restart: unless-stopped
ports:
- "8002:8002"
depends_on:
- browserless
links:
- browserless
browserless:
image: browserless/chrome:latest
environment:
- DEBUG=browserless:*
- MAX_CONCURRENT_SESSIONS=10
- CONNECTION_TIMEOUT=60000
- MAX_QUEUE_LENGTH=20
- PREBOOT_CHROME=true
- DEMO_MODE=false
- HOST=0.0.0.0
- ENABLE_DEBUGGER=false
- PORT=9090
- WORKSPACE_DELETE_EXPIRED=true
container_name: "htmltoimage_server_browserless"
restart: unless-stopped
```
Start the service.
```shell
$ docker compose up -d
```
## Usage
Here is a sample program of how to utilize the service.
```go
package main
import (
"fmt"
"io/ioutil"
"log"
"time"
"github.com/bartmika/htmltoimage-server/pkg/rpc"
)
// NOTE:
// Before you begin running this code, make sure the HTML to Image server is
// running before you execute this program.
func main() {
// Generate the HTML to Image server based on your `docker-compose.yml`.
serverIP := "127.0.0.1"
serverPort := "8002"
applicationAddress := fmt.Sprintf("%s:%s", serverIP, serverPort)
// Connect to a running client.
client, err := rpc.NewClient(applicationAddress, 3, 15*time.Second)
if err != nil {
log.Fatal(err)
}
// Execute the remote call.
imgBin, err := client.Screenshot("https://bartlomiejmika.com")
if err != nil {
log.Fatal("Sample command failed generating image with error:", err)
}
// Save our file.
if err := ioutil.WriteFile("data/screenshot.png", imgBin, 0o644); err != nil {
log.Fatal("Sample command failed writing file with error:", err)
}
log.Println("Saved file: screenshot.png")
}
```
Finally if you look in your `data` folder, you'll see the `screenshot.png` image downloaded!