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 <noreply@anthropic.com>
This commit is contained in:
James 2026-02-28 02:57:27 -05:00
parent 0bfb46206d
commit f8f7f69db8
1 changed files with 12 additions and 0 deletions

12
main.go
View File

@ -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)
}