pkg

package
v0.0.0-...-7442f48 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package pkg contains desprite's implementation.

It can be used independently from the desprite command.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadName = errors.New("filename is empty after sanitation")

ErrBadName is returned when a rule's calculated file name is empty.

View Source
var ErrNonQualified = errors.New("rule must be of type QualifiedRule")

ErrNonQualified is returned when trying to extract a part from a non 'qualified' type rule.

View Source
var ErrOutOfBounds = errors.New("rule leads outside of the sprite bounds")

ErrOutOfBounds is returned when a rule's rectangle is not contained by the sprite.

Functions

func Crop

func Crop(part *Part, sprite image.Image) (image.Image, error)

Crop crops a Part's rect out of an image. If the Part's rect is out of the image bounds, an error is returned.

func ParseCSS

func ParseCSS(cssText string) (*css.Stylesheet, error)

ParseCSS parses a CSS string. It returns the parsed stylesheet or any errors encountered.

func Write

func Write(img image.Image, name string, path string) error

Write encodes an image to PNG and writes to disk with a sanitized filename.

Types

type InvalidRatioError

type InvalidRatioError struct {
	Ratio int
}

InvalidRatioError is the type of error returned when an image ratio is invalid (<=0).

func (*InvalidRatioError) Error

func (e *InvalidRatioError) Error() string

type Part

type Part struct {
	Name string
	Rect *image.Rectangle
}

Part is a named rectangle inside a sprite. It is a sub-image "guess" based on a rectangle-fitting CSS rule.

func Distinct

func Distinct(parts []*Part, considerName bool) []*Part

Distinct filters duplicate rectangles from an array of Parts (last entry wins). If consinderName is true, the Part's name is also considered in the comparison (allowing duplicate rects).

func Find

func Find(rule *css.Rule) (*Part, error)

Find inspects a CSS rule for all properties that usually point to a sprite (width, height, background position). It returns a sprite "Part" or any error making the rule ineligable.

func FindAll

func FindAll(sheet *css.Stylesheet) []*Part

FindAll calls Find for every rule in the stylesheet. It returns all extracted Parts and ignores all errors.

func Scale

func Scale(parts []*Part, ratio int) ([]*Part, error)

Scale scales an array of Parts by a positive int ratio. It turns a rectangle of (x, y, x+w, y+h) to (x, y, x+rw, y+rh).

type UnknownFormatError

type UnknownFormatError struct {
	Scheme string
	Value  string
}

UnknownFormatError is the type of error returned when a declaration's value doesn't match a "useful" format.

func (*UnknownFormatError) Error

func (e *UnknownFormatError) Error() string

type UnrectableError

type UnrectableError struct {
	Missing []string
	Errors  []error
}

UnrectableError is the type of error returned when a rule's declarations are not enough to determine a rect.

func (*UnrectableError) Error

func (e *UnrectableError) Error() string

Jump to

Keyboard shortcuts

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