-
Notifications
You must be signed in to change notification settings - Fork 4
/
jpeg.go
32 lines (26 loc) · 792 Bytes
/
jpeg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Package jpeg implements the builder for JPEG files.
package jpeg
import (
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
"github.com/luabagg/orcgen/internal/generator"
)
// JPEGBuilder struct.
type JPEGBuilder struct {
fullPage bool
}
// GenerateFile converts a rod Page instance to a PNG file.
func (j *JPEGBuilder) GenerateFile(page *rod.Page) ([]byte, error) {
var quality int = 100
req := &proto.PageCaptureScreenshot{
Format: proto.PageCaptureScreenshotFormatJpeg,
Quality: &quality,
FromSurface: false,
}
return page.Screenshot(j.fullPage, req)
}
// SetFullPage sets the pages to be converted. If false, only the first page is selected.
func (j *JPEGBuilder) SetFullPage(fullPage bool) generator.Generator {
j.fullPage = fullPage
return j
}