icns

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

commit d5573f43d43f1fc6dc62d9e678e99d8203a900fd
parent a3aa86930bac291df42872fe6405b6807a0bc635
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Mon, 12 Feb 2018 14:03:23 +0100

[*] Moved image to a param to match other encoding APIs.

Diffstat:
Mcmd/icnsify/main.go | 4++--
Micns.go | 24+++++++++++-------------
2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/cmd/icnsify/main.go b/cmd/icnsify/main.go @@ -54,10 +54,10 @@ func main() { if err != nil { log.Fatalf("decoding image: %v", err) } - enc := icns.NewEncoder(output, img). + enc := icns.NewEncoder(output). WithAlgorithm(algorithm). WithFormat(format) - if err := enc.Encode(); err != nil { + if err := enc.Encode(img); err != nil { log.Fatalf("encoding icns: %v", err) } } diff --git a/icns.go b/icns.go @@ -10,17 +10,15 @@ import ( // Encoder encodes ICNS files from a source image. type Encoder struct { - Wr io.Writer - Image image.Image - Algorithm InterpolationFunction - ImageFormat string + Wr io.Writer + Algorithm InterpolationFunction + Format string } // NewEncoder initialises an encoder. -func NewEncoder(wr io.Writer, img image.Image) *Encoder { +func NewEncoder(wr io.Writer) *Encoder { return &Encoder{ - Wr: wr, - Image: img, + Wr: wr, } } @@ -33,19 +31,19 @@ func (enc *Encoder) WithAlgorithm(a InterpolationFunction) *Encoder { // WithFormat applies the image format identifier used during registration by // image/png and image/jpeg packages. func (enc *Encoder) WithFormat(format string) *Encoder { - enc.ImageFormat = format + enc.Format = format return enc } // Encode icns with the given configuration. -func (enc *Encoder) Encode() error { +func (enc *Encoder) Encode(img image.Image) error { if enc.Wr == nil { return errors.New("cannot write to nil writer") } - if enc.Image == nil { - return errors.New("cannot process nil image") + if img == nil { + return errors.New("cannot encode nil image") } - iconset, err := NewIconSet(enc.Image, enc.Algorithm, enc.ImageFormat) + iconset, err := NewIconSet(img, enc.Algorithm, enc.Format) if err != nil { return err } @@ -60,7 +58,7 @@ func (enc *Encoder) Encode() error { // without preserving the aspect ratio. // Uses nearest neighbor as interpolation algorithm. func Encode(wr io.Writer, img image.Image) error { - return NewEncoder(wr, img).Encode() + return NewEncoder(wr).Encode(img) } // NewIconSet uses the source image to create an IconSet.