wall

package
v0.0.0-...-1561422 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2015 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortPhotoSlice

func SortPhotoSlice(photos []Photo)

SortPhotoSlice sorts a slice of photos

func SortPhotos

func SortPhotos(photos Photos)

SortPhotos sorts photos

Types

type DateNamer

type DateNamer struct {
	// contains filtered or unexported fields
}

DateNamer represents name generator based on date/time

func NewDateNamer

func NewDateNamer(format string) *DateNamer

NewDateNamer generates a new name generator based on date/time

func (*DateNamer) Name

func (n *DateNamer) Name(p Photo) string

Name generates an unique date-based string. Format defines date format e.g. "2006-01-02_150405". Conflicting names are resolved by adding "_1..". Thread-safe

type Namer

type Namer interface {
	Name(Photo) string
}

Namer generates unique names

type NamerFunc

type NamerFunc func(p Photo) string

NamerFunc can be used instead of the Namer type

func (NamerFunc) Name

func (n NamerFunc) Name(p Photo) string

Name transforms NamerFunc to a Namer

type Observer

type Observer func(p Photo)

Observer gets notified if something changes on the wall

type Photo

type Photo interface {
	Name() string
	Bounds() image.Rectangle // width, height
	Format() string          // png, jpeg
	CreatedAt() time.Time
}

Photo represents a photo on the photowall

func NewPhoto

func NewPhoto(name string, width, height int, format string, createdAt time.Time) Photo

NewPhoto creates a new photo

type Photos

type Photos []Photo

Photos is a collection of photos

func (Photos) Len

func (s Photos) Len() int

Len returns length of photo collection

func (Photos) Less

func (s Photos) Less(i, j int) bool

Less checks if photo at index i is created before photo at index j

func (Photos) Swap

func (s Photos) Swap(i, j int)

Swap swaps two photos inside the collection by its indices

type Photowall

type Photowall interface {
	AddPhotoFromFile(name string, createdAt time.Time) error
	AddPhoto(p Photo) error
	RemovePhoto(photo Photo)
	OnAdd(o Observer)
	OnRemove(o Observer)
	Photos() Photos
}

Photowall represents a wall of photos

type Processor

type Processor interface {
	Process(p Photo) (Photo, error)
}

Processor is used to transform photos in a pipeline like resizing and checksumming

func Importer

func Importer() Processor

Importer creates a processor, checking the file for valid image

type ProcessorFunc

type ProcessorFunc func(p Photo) (Photo, error)

ProcessorFunc can be used instead of the Processor type

func (ProcessorFunc) Process

func (f ProcessorFunc) Process(p Photo) (Photo, error)

Process transforms ProcessorFunc to a Processor

type Resizer

type Resizer struct {
	MaxWidth  uint
	MaxHeight uint
}

Resizer resizes photos

func NewResizer

func NewResizer(maxWidth, maxHeight uint) Resizer

NewResizer creates a new instance of Resizer

func (Resizer) Process

func (r Resizer) Process(p Photo) (Photo, error)

Process starts the resizing of the photo

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store processes photos, stores them inside a given directory and checks for duplicates

func NewStore

func NewStore(directory string) *Store

NewStore creates a new store processor

func (*Store) Process

func (s *Store) Process(p Photo) (Photo, error)

Process copy the photo to the store directory and discard it if it's a dup

func (*Store) SetNamer

func (s *Store) SetNamer(namer Namer)

SetNamer sets the Namer for filenames

type Wall

type Wall struct {
	// contains filtered or unexported fields
}

Wall represents a collection of photos, create with Create

func Create

func Create() *Wall

Create a new photowall

Processors should be set after creation

wall.SetProcessors([]Processor{
		NewResizer(1920, 1080),
		NewStore("./storage"),
})

func (*Wall) AddPhoto

func (w *Wall) AddPhoto(p Photo) error

AddPhoto adds a new photo to the wall

func (*Wall) AddPhotoFromFile

func (w *Wall) AddPhotoFromFile(name string, createdAt time.Time) error

AddPhotoFromFile adds a new photo to the wall

func (*Wall) OnAdd

func (w *Wall) OnAdd(o Observer)

OnAdd registers an Observer which is called when a photo was added to the wall

func (*Wall) OnRemove

func (w *Wall) OnRemove(o Observer)

OnRemove registers an Observer which is called when a photo was removed to the wall

func (Wall) Photos

func (w Wall) Photos() Photos

Photos returns all photos on the wall

func (*Wall) Processors

func (w *Wall) Processors() []Processor

Processors returns the list of registered processors

func (*Wall) RemovePhoto

func (w *Wall) RemovePhoto(photo Photo)

RemovePhoto removes a photo from the wall

func (*Wall) SetProcessors

func (w *Wall) SetProcessors(ps []Processor)

SetProcessors sets the list of registered processors

Jump to

Keyboard shortcuts

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