Documentation
¶
Overview ¶
Package icns implements an encoder for Apple's `.icns` file format. Reference: "https://en.wikipedia.org/wiki/Apple_Icon_Image_format".
icns files allow for high resolution icons to make your apps look sexy. The most common ways to generate icns files are 1. use `iconutil` which is a Mac native cli utility, or 2. use tools that wrap `ImageMagick` which adds a large dependency to your project for such a simple use case.
With this library you can use pure Go to create icns files from any source image, given that you can decode it into an `image.Image`, without any heavyweight dependencies or subprocessing required. You can also use this library to create icns files on windows and linux.
A small CLI app `icnsify` is provided to allow you to create icns files using this library from the command line. It supports piping, which is something `iconutil` does not do, making it substantially easier to wrap.
Note: All icons within the icns are sized for high dpi retina screens, using the appropriate icns OSTypes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode finds the largest icon listed in the icns file and returns it, ignoring all other sizes. The format returned will be PNG. JPEG 2000 icons are ignored due to lack of image decoding support.
Types ¶
type Encoder ¶
type Encoder struct {
Wr io.Writer
Algorithm InterpolationFunction
}
Encoder encodes ICNS files from a source image.
func (*Encoder) WithAlgorithm ¶
func (enc *Encoder) WithAlgorithm(a InterpolationFunction) *Encoder
WithAlgorithm applies the interpolation function used to resize the image.
type ErrImageTooSmall ¶
type ErrImageTooSmall struct {
// contains filtered or unexported fields
}
ErrImageTooSmall is returned when the image is too small to process.
func (ErrImageTooSmall) Error ¶
func (err ErrImageTooSmall) Error() string
type IconDescription ¶ added in v3.0.1
type IconDescription struct {
OsType
ImageFormat
}
IconDescription describes an icon.
func Probe ¶ added in v3.0.1
func Probe(r io.Reader) (desc []IconDescription, _ error)
Probe extracts descriptions of the icons in the icns.
func (IconDescription) String ¶ added in v3.0.1
func (desc IconDescription) String() string
type IconSet ¶
type IconSet struct {
Icons []*Icon
// contains filtered or unexported fields
}
IconSet encodes a set of icons into an ICNS file.
func NewIconSet ¶
func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error)
NewIconSet uses the source image to create an IconSet. If width != height, the image will be resized using the largest side without preserving the aspect ratio.
type ImageFormat ¶ added in v3.0.1
type ImageFormat int
ImageFormat specifies the type of image data associated with an icon.
const ( ImageFormatPNG ImageFormat = iota ImageFormatJPEG2000 )
func (ImageFormat) String ¶ added in v3.0.1
func (f ImageFormat) String() string
type InterpolationFunction ¶
type InterpolationFunction = resize.InterpolationFunction
InterpolationFunction is the algorithm used to resize the image.
const ( // Nearest-neighbor interpolation NearestNeighbor InterpolationFunction = iota // Bilinear interpolation Bilinear // Bicubic interpolation (with cubic hermite spline) Bicubic // Mitchell-Netravali interpolation MitchellNetravali // Lanczos interpolation (a=2) Lanczos2 // Lanczos interpolation (a=3) Lanczos3 )
InterpolationFunction constants.
