From d905704a2a77ec6e2398819438d9fe8f494f085f Mon Sep 17 00:00:00 2001 From: Antoni Sawicki Date: Thu, 30 May 2019 18:08:48 -0700 Subject: [PATCH] add width height and scale input boxes --- wrp.go | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/wrp.go b/wrp.go index d700209..4e7d5a7 100644 --- a/wrp.go +++ b/wrp.go @@ -36,22 +36,34 @@ var ( gifmap = make(map[string]bytes.Buffer) ) -func pageServer(out http.ResponseWriter, req *http.Request) { - req.ParseForm() - furl := req.Form["url"] - var gourl string - if len(furl) >= 1 && len(furl[0]) > 4 { - gourl = furl[0] - } else { - gourl = "https://www.bbc.com/news" +func pageServer(out http.ResponseWriter, r *http.Request) { + r.ParseForm() + u := r.FormValue("url") + w, _ := strconv.ParseInt(r.FormValue("w"), 10, 64) + if w < 10 { + w = 1024 } - log.Printf("%s Page Reqest for %s [%s]\n", req.RemoteAddr, gourl, req.URL.Path) + h, _ := strconv.ParseInt(r.FormValue("h"), 10, 64) + if h < 10 { + h = 768 + } + s, _ := strconv.ParseFloat(r.FormValue("s"), 64) + if s < 0.1 { + s = 1.0 + } + log.Printf("%s Page Reqest for url=\"%s\" [%s]\n", r.RemoteAddr, u, r.URL.Path) out.Header().Set("Content-Type", "text/html") - fmt.Fprintf(out, "\nWRP %s\n", gourl) - fmt.Fprintf(out, "
URL: ", gourl) - fmt.Fprintf(out, "

\n") - if len(gourl) > 4 { - capture(gourl, out) + fmt.Fprintf(out, "\nWRP %s\n", u) + fmt.Fprintf(out, "

URL: ", u) + fmt.Fprintf(out, "

\n") + fmt.Fprintf(out, "Width: \n", w) + fmt.Fprintf(out, "Height: \n", h) + fmt.Fprintf(out, "Scale: \n", s) + fmt.Fprintf(out, "

") + if len(u) > 4 { + capture(u, w, h, s, out) + } else { + fmt.Fprintf(out, "No URL specified") } fmt.Fprintf(out, "\n\n") } @@ -75,7 +87,7 @@ func haltServer(out http.ResponseWriter, req *http.Request) { os.Exit(0) } -func capture(gourl string, out http.ResponseWriter) { +func capture(gourl string, w int64, h int64, s float64, out http.ResponseWriter) { var nodes []*cdp.Node ctxx := chromedp.FromContext(ctx) var pngbuf []byte @@ -86,7 +98,7 @@ func capture(gourl string, out http.ResponseWriter) { // Run ChromeDP Magic chromedp.Run(ctx, - emulation.SetDeviceMetricsOverride(1024, 768, 1.0, false), + emulation.SetDeviceMetricsOverride(w, h, s, false), chromedp.Navigate(gourl), chromedp.Sleep(time.Second*2), chromedp.CaptureScreenshot(&pngbuf),