icns

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

commit 816e624c745694df4f3f7aa74b78b7211e394d84
parent 38c96fa1f43944821a92515e958111ca72d1df56
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Wed, 16 Sep 2026 21:30:03 -0400

icns: measure images by their dimensions, not their bounds

An image whose bounds do not start at the origin, such as a SubImage,
reported its far corner as its size. That selected too large an icon tier and
upscaled the source, and the too-small error printed the wrong dimensions.

Diffstat:
Merror.go | 4++--
Micns.go | 10+++-------
2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/error.go b/error.go @@ -29,7 +29,7 @@ type ErrImageTooSmall struct { } func (err ErrImageTooSmall) Error() string { - b := err.image.Bounds().Max + b := err.image.Bounds() format := "image is too small: %dx%d, need at least %dx%d" - return fmt.Sprintf(format, b.X, b.Y, err.need, err.need) + return fmt.Sprintf(format, b.Dx(), b.Dy(), err.need, err.need) } diff --git a/icns.go b/icns.go @@ -123,15 +123,11 @@ func findNearestSize(img image.Image) uint { return 0 } +// biggestSide returns the larger dimension of img. Bounds need not start at +// the origin, so measure the rectangle rather than its far corner. func biggestSide(img image.Image) uint { - var size uint b := img.Bounds() - w, h := uint(b.Max.X), uint(b.Max.Y) - size = w - if h > size { - size = h - } - return size + return uint(max(b.Dx(), b.Dy(), 0)) } // sizesFrom returns a slice containing the sizes less than and including max.