photo

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxWidth  uint = 3840
	DefaultMaxHeight uint = 3840
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Creator

type Creator struct {
	Name string `yaml:"name"`
	Link string `yaml:"link"`
}

Creator contains the metadata about the creator of a photo.

type Info

type Info struct {
	// Key is a special value that is usually set.
	Key string

	// Meta is the photo metadata.
	*Meta

	// File, if not nil, holds a reference to a file handle open for reading the
	// image.
	*os.File
}

Info is the information about a photo. It combines the cache key, the loaded photo metadata, and the file handle to the JPEG.

func (*Info) Close

func (pi *Info) Close() error

Close ensures the file handle is closed, if present. Should always be called when done with the photo info.

func (*Info) HasDownload

func (pi *Info) HasDownload() bool

HasPhoto returns true if the photo info has a downloaded file to work with.

type Meta

type Meta struct {
	Link  string `yaml:"link"`
	Type  string `yaml:"type"`
	Title string `yaml:"title,omitempty"`
	Color string `yaml:"color,omitempty"`
	Creator
}

Meta contains the metadata about a photo.

func (*Meta) GetColor added in v0.4.0

func (m *Meta) GetColor() (color.Color, error)

GetColor returns a color.Color after decoding the CSS string stored. Returns nil and an error if the color cannot be decoded. Returns nil with no error if the color is not set.

func (*Meta) SetColor added in v0.4.0

func (m *Meta) SetColor(c color.Color)

SetColor sets the color as a CSS string from a color.Color.

type Option

type Option func(*options)

func MaxHeight

func MaxHeight(h uint) Option

func MaxWidth

func MaxWidth(w uint) Option

type Service

type Service struct {
	Source
	Client *http.Client
}

func NewService

func NewService(s Source) *Service

func (*Service) DominantImageColor

func (s *Service) DominantImageColor(
	ctx context.Context,
	photo *Info,
) (color.Color, error)

DominantImageColor returns a resized version of the photo if it is larger than the maximum width and height I have set.

func (*Service) Download

func (s *Service) Download(
	ctx context.Context,
	info *Info,
) error

Download fetches file.

func (*Service) Photo

func (s *Service) Photo(
	ctx context.Context,
	photoUrl string,
) (*Info, error)

Meta returns the photo info for a given photo URL. It will cache the photo info in the local filesystem and in S3.

func (*Service) ResizedImage

func (s *Service) ResizedImage(
	ctx context.Context,
	info *Info,
	opts ...Option,
) (*os.File, error)

ResizedImage returns a resized version of the photo if it is larger than the maximum width and height I have set.

type Source

type Source interface {
	// CacheKey returns the cache key for a given URL. If the source does not
	// have a value for the URL, it returns false.
	CacheKey(url string) (string, bool)

	// Meta returns the photo info for a given URL.
	Photo(ctx context.Context, url string) (info *Info, err error)

	// Download downloads the photo and attaches it to the given Info.
	Download(ctx context.Context, info *Info) error
}

Source is the interface for a source of photo information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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