From f8f7f69db817101faf9ac7bef8b1a75c1bfbab56 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 28 Feb 2026 02:57:27 -0500 Subject: [PATCH] Resize captures to 50% before serving Uses sips to halve the image width, reducing transfer size and downstream processing cost. Co-Authored-By: Claude Opus 4.6 --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 65a4ef3..75a3f19 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,9 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "sort" + "strconv" "strings" "time" ) @@ -132,6 +134,16 @@ func captureHandler(w http.ResponseWriter, r *http.Request) { return } + // Resize to 50% using sips + if out, err := exec.Command("sips", "-g", "pixelWidth", tmpFile).Output(); err == nil { + re := regexp.MustCompile(`pixelWidth:\s*(\d+)`) + if m := re.FindSubmatch(out); m != nil { + if w, _ := strconv.Atoi(string(m[1])); w > 0 { + exec.Command("sips", "--resampleWidth", strconv.Itoa(w/2), tmpFile).Run() + } + } + } + log.Printf("Captured display %s", display) serveAndDelete(w, tmpFile) }