Skip to content

Commit 0b1aa5e

Browse files
committed
fix: update icon size validation and compression settings
1 parent 6cabcbc commit 0b1aa5e

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

extension/icon.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ func ResizeExtensionIcon(ctx context.Context, ext Extension) error {
4949
return fmt.Errorf("cannot create icon file: %w", err)
5050
}
5151

52-
if err := png.Encode(writeFile, dst); err != nil {
52+
encoder := png.Encoder{
53+
CompressionLevel: png.BestCompression,
54+
}
55+
56+
if err := encoder.Encode(writeFile, dst); err != nil {
5357
return fmt.Errorf("cannot encode icon: %w", err)
5458
}
5559

extension/platform_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ func TestPluginIconIsTooBig(t *testing.T) {
109109

110110
plugin.Validate(getTestContext(), ctx)
111111

112-
assert.Len(t, ctx.errors, 2)
113-
assert.Equal(t, "The extension icon Resources/config/plugin.png is bigger than 50kb", ctx.errors[0].Message)
114-
assert.Equal(t, "The extension icon Resources/config/plugin.png dimensions (1000x1000) are larger than maximum 256x256 pixels with max file size 50kb and 72dpi", ctx.errors[1].Message)
112+
assert.Len(t, ctx.errors, 1)
113+
assert.Equal(t, "The extension icon Resources/config/plugin.png dimensions (1000x1000) are larger than maximum 256x256 pixels with max file size 30kb and 72dpi", ctx.errors[0].Message)
115114
}
116115

117116
func TestPluginGermanDescriptionMissing(t *testing.T) {

extension/test_helper.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"image"
55
"image/color"
66
"image/png"
7-
"math/rand"
87
"os"
98
)
109

@@ -14,9 +13,16 @@ func createTestImage(path string) error {
1413

1514
func createTestImageWithSize(path string, width, height int) error {
1615
img := image.NewRGBA(image.Rect(0, 0, width, height))
16+
17+
// Create a simple pattern with fewer colors for better compression
1718
for x := 0; x < width; x++ {
1819
for y := 0; y < height; y++ {
19-
img.Set(x, y, color.RGBA{uint8(rand.Intn(255)), uint8(rand.Intn(255)), uint8(rand.Intn(255)), 255})
20+
// Simple checkerboard pattern with just 2 colors
21+
if (x/4+y/4)%2 == 0 {
22+
img.Set(x, y, color.RGBA{220, 220, 220, 255}) // Light gray
23+
} else {
24+
img.Set(x, y, color.RGBA{180, 180, 180, 255}) // Slightly darker gray
25+
}
2026
}
2127
}
2228

@@ -29,5 +35,9 @@ func createTestImageWithSize(path string, width, height int) error {
2935
_ = f.Close()
3036
}()
3137

32-
return png.Encode(f, img)
38+
encoder := png.Encoder{
39+
CompressionLevel: png.BestCompression,
40+
}
41+
42+
return encoder.Encode(f, img)
3343
}

extension/validator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func validateExtensionIcon(ctx *ValidationContext) {
9999
if os.IsNotExist(err) {
100100
ctx.AddError("metadata.icon", fmt.Sprintf("The extension icon %s does not exist", relPath))
101101
} else if err == nil {
102-
if info.Size() > 50*1024 {
103-
ctx.AddError("metadata.icon.size", fmt.Sprintf("The extension icon %s is bigger than 50kb", relPath))
102+
if info.Size() > 30*1024 {
103+
ctx.AddError("metadata.icon.size", fmt.Sprintf("The extension icon %s is bigger than 30kb", relPath))
104104
}
105105

106106
file, err := os.Open(fullIconPath)
@@ -112,9 +112,9 @@ func validateExtensionIcon(ctx *ValidationContext) {
112112
ctx.AddError("metadata.icon", fmt.Sprintf("Could not decode icon image %s: %s", relPath, err.Error()))
113113
} else {
114114
if config.Width < 112 || config.Height < 112 {
115-
ctx.AddError("metadata.icon.size", fmt.Sprintf("The extension icon %s dimensions (%dx%d) are smaller than required 112x112 and maximum 256x256 pixels with max file size 50kb and 72dpi", relPath, config.Width, config.Height))
115+
ctx.AddError("metadata.icon.size", fmt.Sprintf("The extension icon %s dimensions (%dx%d) are smaller than required 112x112 and maximum 256x256 pixels with max file size 30kb and 72dpi", relPath, config.Width, config.Height))
116116
} else if config.Width > 256 || config.Height > 256 {
117-
ctx.AddError("metadata.icon.size", fmt.Sprintf("The extension icon %s dimensions (%dx%d) are larger than maximum 256x256 pixels with max file size 50kb and 72dpi", relPath, config.Width, config.Height))
117+
ctx.AddError("metadata.icon.size", fmt.Sprintf("The extension icon %s dimensions (%dx%d) are larger than maximum 256x256 pixels with max file size 30kb and 72dpi", relPath, config.Width, config.Height))
118118
}
119119
}
120120

0 commit comments

Comments
 (0)