Documentation ¶
Index ¶
- Constants
- func DominantImageColor(ctx context.Context, img image.Image) (color.Color, error)
- func Encode(format string, w io.Writer, img image.Image, opts any) error
- func FilenameForFormat(format, path string) (string, error)
- func FilenameWithoutFormat(format, path string) string
- func PreferredExt(format string) string
- func RegisterEncoder(format string, ext []string, enc EncoderFunc)
- type Complete
- type Creator
- type Descriptor
- type EncoderFunc
- type File
- type Image
- type ImageComplete
- type ImageDecoded
- type ImageReader
- type Memory
- type Option
- type Service
- type Source
Constants ¶
const ( DefaultMaxWidth uint = 3840 DefaultMaxHeight uint = 3840 )
const DefaultFormat = "jpeg"
const (
Original = "original"
)
Variables ¶
This section is empty.
Functions ¶
func DominantImageColor ¶ added in v0.6.0
DominantImageColor returns the dominant color of the image. This is calculated by creating a histogram of all image pixels, then selecting the color that is used the most after excluding pure black and white (unless they are the only possible choices).
func Encode ¶ added in v0.6.0
Encode encodes the image to the given format and writes it to the writer. If the format is empty, the default format is assumed. If the format is not registered, an error is returned.
func FilenameForFormat ¶ added in v0.6.0
FilenameForFormat returns a filename for the given format. If the path already has an extension for the format, the path is returned as is. Otherwise, the path is returned with the extension for the format appended. If the format is empty, the default format is assumed. If the format is not registered, an error is returned.
func FilenameWithoutFormat ¶ added in v0.6.0
FilenameWithoutFormat returns a filename with the format extension removed.
func PreferredExt ¶ added in v0.6.0
func RegisterEncoder ¶ added in v0.6.0
func RegisterEncoder(format string, ext []string, enc EncoderFunc)
Types ¶
type Complete ¶ added in v0.6.0
type Complete struct {
// contains filtered or unexported fields
}
Complete provides a complete implementation of the Image interface, providing ImageDecoded and ImageReader.
type Descriptor ¶ added in v0.6.0
type Descriptor struct { Link string `yaml:"link" json:"link"` Type string `yaml:"type" json:"type"` Title string `yaml:"title,omitempty" json:"title,omitempty"` Color string `yaml:"color,omitempty" json:"color,omitempty"` Creator Creator `yaml:"creator" json:"creator"` // contains filtered or unexported fields }
Descriptor provides metadata data about the image, which is stored in a serialization format on openscripture.today, and also includes a reference to the image file.
func (*Descriptor) AddImage ¶ added in v0.6.0
func (d *Descriptor) AddImage(key string, img Image)
AddImage adds an image to the descriptor.
func (*Descriptor) GetColor ¶ added in v0.6.0
func (d *Descriptor) 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 (*Descriptor) GetImage ¶ added in v0.6.0
func (d *Descriptor) GetImage(key string) ImageComplete
GetImage returns an image from the descriptor.
func (*Descriptor) HasImage ¶ added in v0.6.0
func (d *Descriptor) HasImage(key string) bool
HasImage returns true if the descriptor has an image with the given key.
func (*Descriptor) RemoveImage ¶ added in v0.6.0
func (d *Descriptor) RemoveImage(key string)
RemoveImage removes an image from the descriptor.
func (*Descriptor) SetColor ¶ added in v0.6.0
func (d *Descriptor) SetColor(c color.Color)
SetColor sets the color as a CSS string from a color.Color.
type EncoderFunc ¶ added in v0.6.0
type Image ¶ added in v0.6.0
type Image interface { // Filename is the filename for the image. This may include a directory path // as well. It may be useful as a cache key, so a unique name is preferred. Filename() string }
Image is the interface for a photo image. Every Image must also implemented ImageDecoded or ImageReader.
type ImageComplete ¶ added in v0.6.0
type ImageComplete interface { Image ImageReader ImageDecoded }
ImageComplete is the interface for images that implement Image, ImageReader, and ImageDecoded.
func CompleteImage ¶ added in v0.6.0
func CompleteImage(img Image) ImageComplete
type ImageDecoded ¶ added in v0.6.0
type ImageDecoded interface { // Image returns the image and the format of the image. The format is the // name of the format, like "jpeg" or "png". It should match the registered // format used to decode the image. If the image was not decoded, the format // should be empty. An error should be returned if there's a problem getting // the iamge data. Image() (img image.Image, format string, err error) }
ImageDecoded is the interface that provides the image data in decoded form.
type ImageReader ¶ added in v0.6.0
type ImageReader interface {
Reader() (io.ReadCloser, error)
}
ImageReader is the interface that provides the image data via io.Reader. After reading the image data, the caller must close the reader.
type Service ¶
func NewService ¶
func (*Service) Photo ¶
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, d *Descriptor, opts ...Option, ) (string, error)
ResizedImage returns a resized version of the photo if it is larger than the maximum width and height I have set.