icns

Easily create .icns files (Mac Icons) with this Go library or the included CLI.
Log | Files | Refs | LICENSE

commit 9f7f2ee3b8b529ab9bbd668cb9cf30226f2101c7
parent 535d9c990efe3cbd39175c80a8ada9f2b5cd02cd
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Sat, 29 May 2021 21:26:51 +0800

fix: sort images largest-first

Diffstat:
Mreader.go | 19++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/reader.go b/reader.go @@ -7,6 +7,7 @@ import ( "image" "io" "io/ioutil" + "sort" ) var jpeg2000header = []byte{0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20} @@ -19,13 +20,10 @@ func Decode(r io.Reader) (image.Image, error) { if err != nil { return nil, err } - var biggest iconReader - for _, icon := range icons { - if icon.Size > biggest.Size { - biggest = icon - } - } - img, _, err := image.Decode(biggest.r) + sort.Slice(icons, func(ii, jj int) bool { + return icons[ii].OsType.Size > icons[jj].OsType.Size + }) + img, _, err := image.Decode(icons[0].r) if err != nil { return nil, fmt.Errorf("decoding largest image: %w", err) } @@ -45,6 +43,13 @@ func DecodeAll(r io.Reader) (images []image.Image, err error) { } images = append(images, img) } + sort.Slice(images, func(ii, jj int) bool { + var ( + left = images[ii].Bounds().Size() + right = images[jj].Bounds().Size() + ) + return (left.X * left.Y) > (right.X * right.Y) + }) return images, nil }