Documentation ¶
Index ¶
- Variables
- func CanDecode(ext string) bool
- func Inline(r io.Reader, w io.Writer, encode ...bool) error
- func IsSVG(r io.Reader) bool
- type Imager
- type Options
- type Pos
- type SafeImageMap
- type Sprite
- func (l *Sprite) Decode(rest ...string) error
- func (l *Sprite) Dimensions() Pos
- func (s *Sprite) Export() (abs string, err error)
- func (l *Sprite) File(f string) string
- func (l *Sprite) GetPack(pos int) Pos
- func (l *Sprite) ImageHeight(pos int) int
- func (l *Sprite) ImageWidth(pos int) int
- func (l *Sprite) Len() int
- func (l *Sprite) Lookup(f string) int
- func (l *Sprite) OutputPath() (string, error)
- func (l *Sprite) PackHorizontal(pos int) Pos
- func (l *Sprite) PackVertical(pos int) Pos
- func (l *Sprite) Paths() []string
- func (l *Sprite) SImageHeight(s string) int
- func (l *Sprite) SImageWidth(s string) int
- func (l *Sprite) String() string
- func (s *Sprite) Wait() error
- func (l *Sprite) X(pos int) int
- func (l *Sprite) Y(pos int) int
- type Spriter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFailedToWrite = errors.New("failed to write sprite to disk")
var ErrNoImages = errors.New("no images matched for pattern")
Functions ¶
Types ¶
type Imager ¶ added in v0.9.2
type Imager interface {
Image() *SafeImageMap
}
type Pos ¶
type Pos struct {
X, Y int
}
Pos represents the x, y coordinates of an image in the sprite sheet.
type SafeImageMap ¶
SafeImageMap provides a thread-safe data structure for creating maps of ImageLists
func NewImageMap ¶ added in v0.9.2
func NewImageMap() *SafeImageMap
type Sprite ¶ added in v1.0.0
type Sprite struct { Combined bool // contains filtered or unexported fields }
Example ¶
ExampleSprite shows how to take all the images matching the glob and creating a sprite image in ./test/build/img.
imgs := New(&Options{ ImageDir: ".", BuildDir: "test/build", GenImgDir: "test/build/img", }) err := imgs.Decode("test/1*.png") if err != nil { log.Fatal(err) } fmt.Println(imgs) // Export will start the process of writing the sprite to disk of, err := imgs.Export() if err != nil { log.Fatal(err) } _ = of // Calls are non-blocking, use Wait() to ensure image encoding has // completed and results are flushed to disk. imgs.Wait()
Output: img/68ca3a.png
func (*Sprite) Decode ¶ added in v1.0.0
Decode accepts a variable number of glob patterns. The ImageDir is assumed to be prefixed to the globs provided.
func (*Sprite) Dimensions ¶ added in v1.0.0
Dimensions is the total W,H pixels of the generate sprite
func (*Sprite) Export ¶ added in v1.0.0
Export returns the output path of the combined sprite and flushes the sprite to disk. This method does not block on disk I/O. See Wait
func (*Sprite) GetPack ¶ added in v1.0.0
GetPack retrieves the Pos of an image in the list of images. TODO: Changing l.Pack will update the positions, but the sprite file will need to be regenerated via Decode.
func (*Sprite) ImageHeight ¶ added in v1.0.0
func (*Sprite) ImageWidth ¶ added in v1.0.0
func (*Sprite) OutputPath ¶ added in v1.0.0
OutputPath generates a unique filename based on the relative path from image directory to build directory and the files matched in the glob lookup. OutputPath is not cache safe.
func (*Sprite) PackHorizontal ¶ added in v1.0.0
PackHorzontal finds the Pos for a horizontally packed sprite
func (*Sprite) PackVertical ¶ added in v1.0.0
PackVertical finds the Pos for a vertically packed sprite
func (*Sprite) SImageHeight ¶ added in v1.0.0
func (*Sprite) SImageWidth ¶ added in v1.0.0
func (*Sprite) String ¶ added in v1.0.0
String is a convenience wrapper to OutputPath returning the relative path to the generated sprite from the build directory.
func (*Sprite) Wait ¶ added in v1.0.0
Wait blocks until sprite is encoded to memory and flushed to disk.
type Spriter ¶ added in v0.9.2
type Spriter interface {
Sprite() *SafeImageMap
}