package main
import (
"bytes"
"fmt"
"git.aionnect.com/aionnect/go-common/utils"
"github.com/cbroglie/mustache"
"io/ioutil"
"os"
"os/exec"
"strconv"
)
const tplStr = `
{{title}}
{{description}}
`
const (
W = 768
H = 1024
)
func main() {
var buf bytes.Buffer
tpl, _ := mustache.ParseString(tplStr)
_ = tpl.FRender(&buf, map[string]string{
"title": "Hello world",
"description": "A test for convert html to jpg",
"url": "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFe8TwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyUFlBM1FKcDlldWgxMDAwMDAwNzAAAgTryl1eAwQAAAAA",
})
tempId := utils.NextId()
htmlFileName := fmt.Sprintf("temp_%d.html", tempId)
imgFileName := fmt.Sprintf("temp_%d.jpg", tempId)
_ = ioutil.WriteFile(htmlFileName, buf.Bytes(), os.ModeAppend)
cmd := exec.Command(`wkhtmltoimage`, `--height`, strconv.Itoa(H), `--width`, strconv.Itoa(W), htmlFileName, imgFileName)
_ = cmd.Run()
// output, err := cmd.CombinedOutput()
}