spritewell

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2015 License: MIT Imports: 24 Imported by: 0

README

spritewell

Circle CI

Spritewell performs image composition on a glob of source images. This is useful for creating spritesheets of images. This is a thread safe library and is optimized for multicore systems.

Documentation available at: http://godoc.org/github.com/wellington/spritewell

Currently two different types of positioning are available, Horizontal and Vertical. Padding between images is also supported.

This project does the heavily lifting of image processing for Wellington.

To use spritewell: http://godoc.org/github.com/wellington/spritewell#example-Sprite

imgs := New(&Options{
    ImageDir:  ".",
    BuildDir:  "test/build",
    GenImgDir: "test/build/img",
})

imgs.Decode("test/*.png")
of, _ := imgs.OutputPath()
fmt.Println(of)

// Calls are non-blocking, use Wait() to ensure image encoding has
// completed and results are flushed to disk.
imgs.Wait()

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrFailedToWrite = errors.New("failed to write sprite to disk")
View Source
var ErrNoImages = errors.New("no images matched for pattern")

Functions

func CanDecode

func CanDecode(ext string) bool

CanDecode checks if the file extension is supported by spritewell.

func Inline

func Inline(r io.Reader, w io.Writer, encode ...bool) error

Inline accepts an io.Reader and writes to io.Writer. Binary data is base64 encoded, but base64 encoding is optional for svg.

func IsSVG

func IsSVG(r io.Reader) bool

IsSVG attempts to determine if a reader contains an SVG

Types

type Imager added in v0.9.2

type Imager interface {
	Image() *SafeImageMap
}

type Options added in v1.0.0

type Options struct {
	BuildDir, ImageDir, GenImgDir string
	Pack                          string
	Padding                       int // Padding in pixels
}

type Pos

type Pos struct {
	X, Y int
}

Pos represents the x, y coordinates of an image in the sprite sheet.

type SafeImageMap

type SafeImageMap struct {
	sync.RWMutex
	M map[string]*Sprite
}

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 New added in v1.0.0

func New(opts *Options) *Sprite

func (*Sprite) Decode added in v1.0.0

func (l *Sprite) Decode(rest ...string) error

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

func (l *Sprite) Dimensions() Pos

Dimensions is the total W,H pixels of the generate sprite

func (*Sprite) Export added in v1.0.0

func (s *Sprite) Export() (abs string, err error)

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) File added in v1.0.0

func (l *Sprite) File(f string) string

Return relative path to File TODO: Return abs path to file

func (*Sprite) GetPack added in v1.0.0

func (l *Sprite) GetPack(pos int) Pos

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 (l *Sprite) ImageHeight(pos int) int

func (*Sprite) ImageWidth added in v1.0.0

func (l *Sprite) ImageWidth(pos int) int

func (*Sprite) Len added in v1.0.0

func (l *Sprite) Len() int

func (*Sprite) Lookup added in v1.0.0

func (l *Sprite) Lookup(f string) int

func (*Sprite) OutputPath added in v1.0.0

func (l *Sprite) OutputPath() (string, error)

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

func (l *Sprite) PackHorizontal(pos int) Pos

PackHorzontal finds the Pos for a horizontally packed sprite

func (*Sprite) PackVertical added in v1.0.0

func (l *Sprite) PackVertical(pos int) Pos

PackVertical finds the Pos for a vertically packed sprite

func (*Sprite) Paths added in v1.0.0

func (l *Sprite) Paths() []string

func (*Sprite) SImageHeight added in v1.0.0

func (l *Sprite) SImageHeight(s string) int

func (*Sprite) SImageWidth added in v1.0.0

func (l *Sprite) SImageWidth(s string) int

func (*Sprite) String added in v1.0.0

func (l *Sprite) String() string

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

func (s *Sprite) Wait() error

Wait blocks until sprite is encoded to memory and flushed to disk.

func (*Sprite) X added in v1.0.0

func (l *Sprite) X(pos int) int

Return the X position of an image based on the layout (vertical/horizontal) and position in Image slice

func (*Sprite) Y added in v1.0.0

func (l *Sprite) Y(pos int) int

Return the Y position of an image based on the layout (vertical/horizontal) and position in Image slice

type Spriter added in v0.9.2

type Spriter interface {
	Sprite() *SafeImageMap
}

Jump to

Keyboard shortcuts

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