update to work with new monitor

This commit is contained in:
2025-11-30 12:41:45 -08:00
parent b78b6b6582
commit 6031f081cf

View File

@@ -175,7 +175,7 @@ func downloadRandomWallpaper(wallpaperPath string, r *rand.Rand, topics []string
fmt.Fprintf(os.Stderr, "Searching for wallpapers related to: %s\n", displayName) fmt.Fprintf(os.Stderr, "Searching for wallpapers related to: %s\n", displayName)
// Get wallpapers from Wallhaven API // Get wallpapers from Wallhaven API
resp, err := http.Get(fmt.Sprintf("%s/search?q=%s&purity=100&categories=110&sorting=random", wallhavenAPI, query)) resp, err := http.Get(fmt.Sprintf("%s/search?q=%s&purity=100&categories=110&sorting=random&atleast=3440x1440", wallhavenAPI, query))
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error fetching from Wallhaven: %v\n", err) fmt.Fprintf(os.Stderr, "Error fetching from Wallhaven: %v\n", err)
return "", "" return "", ""
@@ -272,11 +272,26 @@ func ensureSized(wallpaperPath string) (string, error) {
return "", err return "", err
} }
if src.Bounds().Dx() == targetWidth && src.Bounds().Dy() == targetHeight { srcWidth := float64(src.Bounds().Dx())
srcHeight := float64(src.Bounds().Dy())
targetW := float64(targetWidth)
targetH := float64(targetHeight)
// Calculate scale factor to fit image within target while maintaining aspect ratio
scaleW := targetW / srcWidth
scaleH := targetH / srcHeight
scale := min(scaleW, scaleH)
// If image already fits within target dimensions, no resize needed
if scale >= 1.0 {
return wallpaperPath, nil return wallpaperPath, nil
} }
dst := image.NewRGBA(image.Rect(0, 0, targetWidth, targetHeight)) // Calculate new dimensions maintaining aspect ratio (best fit)
newWidth := int(srcWidth * scale)
newHeight := int(srcHeight * scale)
dst := image.NewRGBA(image.Rect(0, 0, newWidth, newHeight))
draw.CatmullRom.Scale(dst, dst.Bounds(), src, src.Bounds(), draw.Over, nil) draw.CatmullRom.Scale(dst, dst.Bounds(), src, src.Bounds(), draw.Over, nil)
var ext string var ext string
@@ -295,7 +310,7 @@ func ensureSized(wallpaperPath string) (string, error) {
} }
base := strings.TrimSuffix(filepath.Base(wallpaperPath), filepath.Ext(wallpaperPath)) base := strings.TrimSuffix(filepath.Base(wallpaperPath), filepath.Ext(wallpaperPath))
resizedPath := filepath.Join(filepath.Dir(wallpaperPath), fmt.Sprintf("%s-%dx%d%s", base, targetWidth, targetHeight, ext)) resizedPath := filepath.Join(filepath.Dir(wallpaperPath), fmt.Sprintf("%s-%dx%d%s", base, newWidth, newHeight, ext))
outFile, err := os.Create(resizedPath) outFile, err := os.Create(resizedPath)
if err != nil { if err != nil {