spritesheet

package module
v0.0.0-...-5a5d62f Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: MIT Imports: 3 Imported by: 1

README

Spritesheet

Spritesheet is an Encoder and Decoder to build spritesheets from a list of images or seperate a spritesheet into multiple images.

Encoder

The encoder takes in a slice of images and some options. If no options are provided, defaults will be used.

// EncodeOpts provides the encoder the parameters it needs to create a spritesheet
type EncodeOpts struct {
	New        func(r image.Rectangle) draw.Image // what format you want the new image to be, defaults to RGBA
	ImgsPerRow int // Default to 5
}

// Encode takes a slice of images and based on the encode options will turn
// the images into a single sprite sheet.
// If the images are not all the same size, encode will take the max height
// and max width of any image and use that as its dimensions. For best look,
// all images should be the same size.
func Encode(images []image.Image, opts *EncodeOpts) (image.Image, error) {

Decoder

The decoder takes a spritesheet and based on width and height chops the spritesheet up into a slice of seperate images.

// DecodeOpts provides the decoder with the necessary opts to split the spritesheet into seperate images
type DecodeOpts struct {
	New           func(r image.Rectangle) draw.Image // what format you want the new image to be, defaults to RGBA
	Width, Height int
}

// Decode takes in a image, assumed to be a spritesheet, and based on the options passed will
// chop up the spritesheet into seperate images.
// a width and height are needed to know the bounds of each image
func Decode(in image.Image, opts *DecodeOpts) ([]image.Image, error) {

Scripts

In the scripts you can find a bash script for help creating spritesheets out of video. It uses ffmpeg and the cli found in cmd folder to do this.

options:

Example to create a thumbnail every two seconds.

./scripts/video-thumbnails.sh -i oceans.mp4 -ss 00:00:00.000 -vf 1/2
Sheet_0

sheet_0

Sheet_1

sheet_1

TODO

  • Finish the cli

Documentation

Index

Constants

View Source
const (
	DefaultImgsPerRow = 5
)

Variables

View Source
var (
	ErrNoImages      = errors.New("no images passed to the encoder")
	ErrBadDimensions = errors.New("width and/or height of images passed is zero")
)

Functions

func Decode

func Decode(in image.Image, opts *DecodeOpts) ([]image.Image, error)

Decode takes in a image, assumed to be a spritesheet, and based on the options passed will chop up the spritesheet into seperate images. a width and height are needed to know the bounds of each image

func Encode

func Encode(images []image.Image, opts *EncodeOpts) (image.Image, error)

Encode takes a slice of images and based on the encode options will turn the images into a single sprite sheet. If the images are not all the same size, encode will take the max height and max width of any image and use that as its dimensions. For best look, all images should be the same size.

func NewAlpha

func NewAlpha(r image.Rectangle) draw.Image

NewAlpha returns new image.Alpha

func NewAlpha16

func NewAlpha16(r image.Rectangle) draw.Image

NewAlpha returns new image.Alpha16

func NewCMYK

func NewCMYK(r image.Rectangle) draw.Image

NewCMYK returns new image.CMYK

func NewGray

func NewGray(r image.Rectangle) draw.Image

NewGrey returns new image.Grey

func NewGray16

func NewGray16(r image.Rectangle) draw.Image

NewGray16 returns new image.Gray16

func NewNRGBA

func NewNRGBA(r image.Rectangle) draw.Image

NewNRGBA returns new image.NRGBA

func NewNRGBA64

func NewNRGBA64(r image.Rectangle) draw.Image

NewNRGBA64 returns new image.NRGBA64

func NewRGBA

func NewRGBA(r image.Rectangle) draw.Image

NewRGBA returns new image.NRGBA64

func NewRGBA64

func NewRGBA64(r image.Rectangle) draw.Image

NewRGBA64 returns new image.NewRGBA64

Types

type DecodeOpts

type DecodeOpts struct {
	New           func(r image.Rectangle) draw.Image // what format you want the new image to be, defaults to RGBA
	Width, Height int
}

DecodeOpts provides the decoder with the necessary opts to split the spritesheet into seperate images

type EncodeOpts

type EncodeOpts struct {
	New        func(r image.Rectangle) draw.Image // what format you want the new image to be, defaults to RGBA
	ImgsPerRow int
}

EncodeOpts provides the encoder the parameters it needs to create a sprite sheet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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