Browse Source

Resize favicons to 32x32 to account of scaling

As suggested by @michaelkuhn in https://github.com/miniflux/v2/pull/2998#issuecomment-2546702212
jvoisin 1 năm trước cách đây
mục cha
commit
7939b54341
2 tập tin đã thay đổi với 5 bổ sung5 xóa
  1. 2 2
      internal/reader/icon/finder.go
  2. 3 3
      internal/reader/icon/finder_test.go

+ 2 - 2
internal/reader/icon/finder.go

@@ -206,7 +206,7 @@ func resizeIcon(icon *model.Icon) *model.Icon {
 		slog.Warn("unable to decode the metadata of the icon", slog.Any("error", err))
 		return icon
 	}
-	if config.Height <= 16 && config.Width <= 16 {
+	if config.Height <= 32 && config.Width <= 32 {
 		slog.Debug("icon don't need to be rescaled", slog.Int("height", config.Height), slog.Int("width", config.Width))
 		return icon
 	}
@@ -227,7 +227,7 @@ func resizeIcon(icon *model.Icon) *model.Icon {
 		return icon
 	}
 
-	dst := image.NewRGBA(image.Rect(0, 0, 16, 16))
+	dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
 	draw.BiLinear.Scale(dst, dst.Rect, src, src.Bounds(), draw.Over, nil)
 
 	var b bytes.Buffer

+ 3 - 3
internal/reader/icon/finder_test.go

@@ -146,7 +146,7 @@ func TestResizeIconSmallGif(t *testing.T) {
 }
 
 func TestResizeIconPng(t *testing.T) {
-	data, err := base64.StdEncoding.DecodeString("iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAHElEQVR42mP8z/C/noFCwDhqyKgho4aMGkIlQwBrHSpf28Yx+gAAAABJRU5ErkJggg==")
+	data, err := base64.StdEncoding.DecodeString("iVBORw0KGgoAAAANSUhEUgAAACEAAAAhCAYAAABX5MJvAAAALUlEQVR42u3OMQEAAAgDoJnc6BpjDyRgcrcpGwkJCQkJCQkJCQkJCQkJCYmyB7NfUj/Kk4FkAAAAAElFTkSuQmCC")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -157,7 +157,7 @@ func TestResizeIconPng(t *testing.T) {
 	resizedIcon := resizeIcon(&icon)
 
 	if bytes.Equal(data, resizedIcon.Content) {
-		t.Fatalf("Didn't convert png of 17x17")
+		t.Fatalf("Didn't convert png of 33x33")
 	}
 
 	config, _, err := image.DecodeConfig(bytes.NewReader(resizedIcon.Content))
@@ -165,7 +165,7 @@ func TestResizeIconPng(t *testing.T) {
 		t.Fatalf("Couln't decode resulting png: %v", err)
 	}
 
-	if config.Height != 16 || config.Width != 16 {
+	if config.Height != 32 || config.Width != 32 {
 		t.Fatalf("Was expecting an image of 16x16, got %dx%d", config.Width, config.Height)
 	}
 }