add support for monochrome 2 colors

This commit is contained in:
debounce 2020-09-28 12:19:27 -07:00
parent ac594cdebd
commit 36427fac64
1 changed files with 5 additions and 0 deletions

5
wrp.go
View File

@ -27,6 +27,7 @@ import (
"syscall"
"time"
"github.com/MaxHalford/halfgone"
"github.com/chromedp/cdproto/css"
"github.com/chromedp/cdproto/emulation"
"github.com/chromedp/cdproto/page"
@ -357,6 +358,10 @@ func (w wrpReq) capture() {
fmt.Fprintf(w.out, "<BR>Unable to decode page screenshot:<BR>%s<BR>\n", err)
return
}
if w.colors == 2 {
gray := halfgone.ImageToGray(i)
i = halfgone.FloydSteinbergDitherer{}.Apply(gray)
}
var gifbuf bytes.Buffer
err = gif.Encode(&gifbuf, i, &gif.Options{NumColors: int(w.colors), Quantizer: quantize.MedianCutQuantizer{}})
if err != nil {