From 79abcb72fb88808d88ef8e82dfb0a895097da572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Fr=C3=B6hle?= Date: Thu, 16 Jan 2020 11:59:44 +0100 Subject: [PATCH] Change Images for Debug Mode --- configuration.go | 4 ++++ content_functions.go | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/configuration.go b/configuration.go index 4e65942..76e388e 100644 --- a/configuration.go +++ b/configuration.go @@ -4,6 +4,7 @@ import ( "regexp" "github.com/chromedp/cdproto/cdp" + "github.com/chromedp/cdproto/page" "github.com/robfig/cron/v3" ) @@ -30,6 +31,9 @@ const ( fbPageURL string = "https://www.facebook.com/herowarsgame/" // fbGameURL for search on expaned urls fbGameURL string = "apps.facebook.com/mobaheroes" + + imageQuality int64 = 85 + imageFormat page.CaptureScreenshotFormat = page.CaptureScreenshotFormatJpeg ) // Constants for title of the Postings diff --git a/content_functions.go b/content_functions.go index 5662027..3050ca5 100644 --- a/content_functions.go +++ b/content_functions.go @@ -25,11 +25,11 @@ func makeScreenShot(c context.Context, page string) { if viper.GetBool("development_mode") { // capture entire browser viewport, returning png with quality=90 - if err := chromedp.Run(c, fullScreenshot(90, &buf, &content)); err != nil { + if err := chromedp.Run(c, fullScreenshot(imageQuality, &buf, &content)); err != nil { //log.Fatal(err) } - if err := ioutil.WriteFile("/opt/tmp/"+timeNow+"-"+page+"-fullScreenshot.png", buf, 0644); err != nil { + if err := ioutil.WriteFile("/opt/tmp/"+timeNow+"-"+page+"-fullScreenshot.jpeg", buf, 0644); err != nil { //log.Fatal(err) } @@ -48,12 +48,12 @@ func makeScreenShotAndParsePost(c context.Context, page string) (*FBPostData, er var content string // capture entire browser viewport, returning png with quality=90 - if err := chromedp.Run(c, fullScreenshot(90, &buf, &content)); err != nil { + if err := chromedp.Run(c, fullScreenshot(imageQuality, &buf, &content)); err != nil { //log.Fatal(err) } if viper.GetBool("development_mode") { - if err := ioutil.WriteFile("/opt/tmp/"+timeNow+"-"+page+"-fullScreenshot.png", buf, 0644); err != nil { + if err := ioutil.WriteFile("/opt/tmp/"+timeNow+"-"+page+"-fullScreenshot.jpeg", buf, 0644); err != nil { //log.Fatal(err) } @@ -74,11 +74,11 @@ func makeScreenShotOnly(c context.Context, page string) { if viper.GetBool("development_mode") { // capture entire browser viewport, returning png with quality=90 - if err := chromedp.Run(c, fullScreenshotOnly(90, &buf)); err != nil { + if err := chromedp.Run(c, fullScreenshotOnly(imageQuality, &buf)); err != nil { //log.Fatal(err) } - if err := ioutil.WriteFile("/opt/tmp/"+timeNow+"-"+page+"-fullScreenshot.png", buf, 0644); err != nil { + if err := ioutil.WriteFile("/opt/tmp/"+timeNow+"-"+page+"-fullScreenshot.jpeg", buf, 0644); err != nil { //log.Fatal(err) } } @@ -115,6 +115,7 @@ func fullScreenshot(quality int64, res *[]byte, content *string) chromedp.Tasks // capture screenshot *res, err = page.CaptureScreenshot(). + WithFormat(imageFormat). WithQuality(quality). WithClip(&page.Viewport{ X: contentSize.X, @@ -162,6 +163,7 @@ func fullScreenshotOnly(quality int64, res *[]byte) chromedp.Tasks { // capture screenshot *res, err = page.CaptureScreenshot(). + WithFormat(imageFormat). WithQuality(quality). WithClip(&page.Viewport{ X: contentSize.X,