fix: (Windows) Replace ICO decoder for improved icon extraction
Implemented direct use of `sergeymakinen/go-ico` decoder instead of `mat/besticon/ico` for icon conversion. The standard `image.Decode()` and `mat/besticon/ico` approaches failed with certain ICO files, particularly those containing cursor data from Windows executable resources. This change ensures more reliable handling of various ICO format variants.
This commit is contained in:
@@ -3,17 +3,22 @@ package binmeta
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/png" // Register png support for image package
|
||||
|
||||
"github.com/fogleman/gg"
|
||||
_ "github.com/mat/besticon/ico" // Register ico support for image package
|
||||
|
||||
// Import the specialized ICO decoder package
|
||||
// This package seems to work better than "github.com/mat/besticon/ico" with ICO files
|
||||
// extracted from Windows binaries, particularly those containing cursor-related data
|
||||
ico "github.com/sergeymakinen/go-ico"
|
||||
)
|
||||
|
||||
// ConvertICOtoPNG converts a an .ico to a .png image.
|
||||
func ConvertICOtoPNG(ico []byte) (png []byte, err error) {
|
||||
// Decode the ICO.
|
||||
icon, _, err := image.Decode(bytes.NewReader(ico))
|
||||
func ConvertICOtoPNG(icoBytes []byte) (png []byte, err error) {
|
||||
// Decode ICO image.
|
||||
// Note: The standard approach with `image.Decode(bytes.NewReader(icoBytes))` sometimes fails
|
||||
// when processing certain ICO files (particularly those with cursor data),
|
||||
// as it reads initial bytes for format detection before passing the stream to the decoder.
|
||||
icon, err := ico.Decode(bytes.NewReader(icoBytes))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode ICO: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user