From 791e87d7ed47fa553a7b32343220d9dbea83ed64 Mon Sep 17 00:00:00 2001 From: Antoni Sawicki Date: Sun, 2 Jun 2019 17:06:41 -0700 Subject: [PATCH] added number of colors --- wrp.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/wrp.go b/wrp.go index 826e6fb..b4b64a9 100644 --- a/wrp.go +++ b/wrp.go @@ -83,30 +83,35 @@ func pageServer(out http.ResponseWriter, req *http.Request) { if s < 0.1 { s = 1.0 } + c, _ := strconv.ParseInt(req.FormValue("c"), 10, 64) + if c < 2 || c > 256 { + c = 256 + } log.Printf("%s Page Reqest for url=\"%s\" [%s]\n", req.RemoteAddr, u, req.URL.Path) out.Header().Set("Content-Type", "text/html") fmt.Fprintf(out, "\n", version) fmt.Fprintf(out, "\nWRP %s\n\n", u) - fmt.Fprintf(out, "
URL/Search: ", u) - fmt.Fprintf(out, "

\n") + fmt.Fprintf(out, "URL/Search: ", u) + fmt.Fprintf(out, " \n") + fmt.Fprintf(out, "Page: \n") + fmt.Fprintf(out, " \n", p) + fmt.Fprintf(out, "

\n") fmt.Fprintf(out, "ISMAP: \n", istr) fmt.Fprintf(out, "Width: \n", w) fmt.Fprintf(out, "Height: \n", h) fmt.Fprintf(out, "Scale: \n", s) - fmt.Fprintf(out, "Page: \n", p) - fmt.Fprintf(out, " %d \n", p) - fmt.Fprintf(out, " \n") + fmt.Fprintf(out, "Colors: \n", c) fmt.Fprintf(out, "

\n") if len(u) > 4 { if strings.HasPrefix(u, "http") { - capture(u, w, h, s, p, i, req.RemoteAddr, out) + capture(u, w, h, s, int(c), p, i, req.RemoteAddr, out) } else { - capture(fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(u)), w, h, s, p, i, req.RemoteAddr, out) + capture(fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(u)), w, h, s, int(c), p, i, req.RemoteAddr, out) } } else { fmt.Fprintf(out, "No URL or search query specified") } - fmt.Fprintf(out, "\n

Web Rendering Proxy Version %s\n\n", w, h, s, ion, version) + fmt.Fprintf(out, "\n

Web Rendering Proxy Version %s\n\n", w, h, s, c, ion, version) } func imgServer(out http.ResponseWriter, req *http.Request) { @@ -152,7 +157,7 @@ func haltServer(out http.ResponseWriter, req *http.Request) { os.Exit(0) } -func capture(gourl string, w int64, h int64, s float64, p int64, i bool, c string, out http.ResponseWriter) { +func capture(gourl string, w int64, h int64, s float64, co int, p int64, i bool, c string, out http.ResponseWriter) { var nodes []*cdp.Node ctxx := chromedp.FromContext(ctx) var pngbuf []byte @@ -191,7 +196,7 @@ func capture(gourl string, w int64, h int64, s float64, p int64, i bool, c strin return } gifbuf.Reset() - err = gif.Encode(&gifbuf, img, nil) + err = gif.Encode(&gifbuf, img, &gif.Options{NumColors: co}) if err != nil { log.Printf("%s Failed to encode GIF: %s\n", c, err) fmt.Fprintf(out, "
Unable to encode GIF:
%s
\n", err) @@ -207,7 +212,7 @@ func capture(gourl string, w int64, h int64, s float64, p int64, i bool, c strin base, _ := url.Parse(loc) if i { fmt.Fprintf(out, "\"wrp\"", mappath, imgpath) - is = append(is, Ismap{xmin: -1, xmax: -1, ymin: -1, ymax: -1, url: fmt.Sprintf("/?url=%s&w=%d&h=%d&s=%1.2f&i=on", loc, w, h, s)}) + is = append(is, Ismap{xmin: -1, xmax: -1, ymin: -1, ymax: -1, url: fmt.Sprintf("/?url=%s&w=%d&h=%d&s=%1.2f&c=%d&i=on", loc, w, h, s, co)}) ion = "&i=on" } else { fmt.Fprintf(out, "\"wrp\"\n\n", imgpath) @@ -222,7 +227,7 @@ func capture(gourl string, w int64, h int64, s float64, p int64, i bool, c strin if err != nil { continue } - target := fmt.Sprintf("/?url=%s&w=%d&h=%d&s=%1.2f%s", tgt, w, h, s, ion) // no page# here + target := fmt.Sprintf("/?url=%s&w=%d&h=%d&s=%1.2f&c=%d%s", tgt, w, h, s, co, ion) // no page# here if len(b.Content) > 6 && len(target) > 7 { if i {