icns

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

commit 06d66d56f26c90ce4a208d23fbf2316c397ee336
parent 3fb89f01cc66991393b1ba86c0005e33f84f9953
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Sat, 10 Feb 2018 15:30:05 +0100

[*] Added sanity checks.

Diffstat:
Micns.go | 9+--------
Minterpolation.go | 7+++++++
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/icns.go b/icns.go @@ -12,14 +12,7 @@ import ( // without preserving the aspect ratio. // Uses nearest neighbor as interpolation algorithm. func Encode(wr io.Writer, img image.Image) error { - iconset, err := NewIconSet(img, NearestNeighbor) - if err != nil { - return err - } - if _, err := iconset.WriteTo(wr); err != nil { - return err - } - return nil + return EncodeWithInterpolationFunction(wr, img, NearestNeighbor) } // NewIconSet uses the source image to create an IconSet. diff --git a/interpolation.go b/interpolation.go @@ -1,6 +1,7 @@ package icns import ( + "errors" "image" "io" @@ -33,6 +34,12 @@ func EncodeWithInterpolationFunction( img image.Image, interp InterpolationFunction, ) error { + if wr == nil { + return errors.New("cannot write to nil writer") + } + if img == nil { + return errors.New("cannot process nil image") + } iconset, err := NewIconSet(img, interp) if err != nil { return err