icns

package
v0.2.72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Icns

Easily convert .jpg and .png to .icns with the command line tool icnsify, or use the library to convert from any image.Image to .icns.

func main() {
        pngf, err := os.Open("path/to/icon.png")
        if err != nil {
                log.Fatalf("opening source image: %v", err)
        }
        defer pngf.Close()
        srcImg, _, err := image.Decode(pngf)
        if err != nil {
                log.Fatalf("decoding source image: %v", err)
        }
        dest, err := os.Create("path/to/icon.icns")
        if err != nil {
                log.Fatalf("opening destination file: %v", err)
        }
        defer dest.Close()
        if err := icns.Encode(dest, srcImg); err != nil {
                log.Fatalf("encoding icns: %v", err)
        }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode finds the largest icon listed in the icns file and returns it, ignoring all other sizes. The format returned will be whatever the icon data is, typically jpeg or png.

func DecodeAll

func DecodeAll(r io.Reader) (images []image.Image, err error)

DecodeAll extracts all icon resolutions present in the icns data.

Types

type Encoder

type Encoder struct {
	Wr        io.Writer
	Algorithm InterpolationFunction
}

Encoder encodes ICNS files from a source image.

func NewEncoder

func NewEncoder(wr io.Writer) *Encoder

NewEncoder initialises an encoder.

func (*Encoder) Encode

func (instance *Encoder) Encode(img image.Image) error

Encode icns with the given configuration.

func (*Encoder) WithAlgorithm

func (instance *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 IcnsHelper

type IcnsHelper struct{}
var Icns *IcnsHelper

func (*IcnsHelper) Create

func (instance *IcnsHelper) Create(inputPath, outputPath string, optResizeAlgorithm int) (err error)

func (*IcnsHelper) CreateBicubic

func (instance *IcnsHelper) CreateBicubic(inputPath, outputPath string) (err error)

func (*IcnsHelper) CreateBilinear

func (instance *IcnsHelper) CreateBilinear(inputPath, outputPath string) (err error)

func (*IcnsHelper) CreateLanczos2

func (instance *IcnsHelper) CreateLanczos2(inputPath, outputPath string) (err error)

func (*IcnsHelper) CreateLanczos3

func (instance *IcnsHelper) CreateLanczos3(inputPath, outputPath string) (err error)

func (*IcnsHelper) CreateMitchellNetravali

func (instance *IcnsHelper) CreateMitchellNetravali(inputPath, outputPath string) (err error)

func (*IcnsHelper) CreateNearestNeighbor

func (instance *IcnsHelper) CreateNearestNeighbor(inputPath, outputPath string) (err error)

func (*IcnsHelper) Encode

func (instance *IcnsHelper) Encode(wr io.Writer, img image.Image) error

Encode writes img to wr in ICNS format. img is assumed to be a rectangle; non-square dimensions will be squared without preserving the aspect ratio. Use the nearest neighbor as an interpolation algorithm.

func (*IcnsHelper) NewIconSet

func (instance *IcnsHelper) 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 Icon

type Icon struct {
	Type  OsType
	Image image.Image
	// contains filtered or unexported fields
}

Icon encodes an icns icon.

func (*Icon) WriteTo

func (instance *Icon) WriteTo(wr io.Writer) (int64, error)

WriteTo encodes the icon into wr.

type IconSet

type IconSet struct {
	Icons []*Icon
	// contains filtered or unexported fields
}

IconSet encodes a set of icons into an ICNS file.

func (*IconSet) WriteTo

func (instance *IconSet) WriteTo(wr io.Writer) (int64, error)

WriteTo writes the ICNS file to wr.

type InterpolationFunction

type InterpolationFunction = resize.InterpolationFunction

InterpolationFunction is the algorithm used to resize the image.

const (
	// NearestNeighbor Nearest-neighbor interpolation
	NearestNeighbor InterpolationFunction = iota
	// Bilinear interpolation
	Bilinear
	// Bicubic interpolation (with cubic hermite spline)
	Bicubic
	// MitchellNetravali Mitchell-Netravali interpolation
	MitchellNetravali
	// Lanczos2 Lanczos interpolation (a=2)
	Lanczos2
	// Lanczos3 Lanczos interpolation (a=3)
	Lanczos3
)

InterpolationFunction constants.

type OsType

type OsType struct {
	ID   string
	Size uint
}

OsType is a 4 character identifier used to differentiate icon types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL