Skip to content

Commit

Permalink
Resize favicons to 32x32 to account of scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin authored and WShihan committed Feb 23, 2025
1 parent aaed8da commit 7161a90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/reader/icon/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/reader/icon/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -157,15 +157,15 @@ 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))
if err != nil {
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)
}
}
Expand Down

0 comments on commit 7161a90

Please sign in to comment.