imagemeta

package module
v0.0.0-...-6cbef11 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 10 Imported by: 0

README

Tests on Linux, MacOS and Windows Go Report Card GoDoc

Work in progress

This is not ready, yet, but the goal is to use this as the library to read image metadata in Hugo. The existing Go libraries I have found is not maintained anymore and too complex to build on top of. The goal of this library is to be relatively small and simple, but I may prove myself wrong.

Documentation

Index

Constants

View Source
const UnknownPrefix = "UnknownTag_"

UnknownPrefix is used as prefix for unknown tags.

Variables

View Source
var ErrInvalidFormat = fmt.Errorf("imagemeta: invalid format")

ErrInvalidFormat is returned when the format is not recognized.

View Source
var (
	// ErrStopWalking is a sentinel error to signal that the walk should stop.
	ErrStopWalking = fmt.Errorf("stop walking")
)

Functions

func Decode

func Decode(opts Options) (err error)

Decode reads EXIF and IPTC metadata from r and returns a Meta struct.

Types

type HandleTagFunc

type HandleTagFunc func(info TagInfo) error

HandleTagFunc is the function that is called for each tag.

type ImageFormat

type ImageFormat int
const (
	// ImageFormatAuto signals that the image format should be detected automatically (not implemented yet).
	ImageFormatAuto ImageFormat = iota
	// ImageFormatJPEG is the JPEG image format.
	ImageFormatJPEG
	// ImageFormatTIFF is the TIFF image format.
	ImageFormatTIFF
	// ImageFormatPNG is the PNG image format.
	ImageFormatPNG
	// ImageFormatWebP is the WebP image format.
	ImageFormatWebP
)

func (ImageFormat) String

func (i ImageFormat) String() string

type Options

type Options struct {
	// The Reader (typically a *os.File) to read image metadata from.
	R Reader

	// The image format in R.
	ImageFormat ImageFormat

	// The function to call for each tag.
	HandleTag HandleTagFunc

	// The default XMP handler is currently very simple:
	// It decodes the RDF.Description.Attrs using Go's xml package and passes each tag to HandleTag.
	// If HandleXMP is set, the decoder will call this function for each XMP packet instead.
	// Note that r must be read completely.
	HandleXMP func(r io.Reader) error

	// If set, the decoder will only read the given tag sources.
	// Note that this is a bitmask and you may send multiple sources at once.
	Sources TagSource
}

type Reader

type Reader interface {
	io.ReadSeeker
	io.ReaderAt
}

Reader is the interface that wraps the basic Read and Seek methods.

type TagInfo

type TagInfo struct {
	// The tag source.
	Source TagSource
	// The tag name.
	Tag string
	// The tag namespace, if any (currently only set for XMP tags.)
	Namespace string
	// The tag value.
	Value any
}

TagInfo contains information about a tag.

type TagSource

type TagSource uint32

TagSource is a bitmask and you may send multiple sources at once.

const (
	// TagSourceEXIF is the EXIF tag source.
	TagSourceEXIF TagSource = 1 << iota
	// TagSourceIPTC is the IPTC tag source.
	TagSourceIPTC
	// TagSourceXMP is the XMP tag source.
	TagSourceXMP
)

func (TagSource) Has

func (t TagSource) Has(source TagSource) bool

Has returns true if the given source is set.

func (TagSource) IsZero

func (t TagSource) IsZero() bool

IsZero returns true if the source is zero.

func (TagSource) Remove

func (t TagSource) Remove(source TagSource) TagSource

Remove removes the given source.

func (TagSource) String

func (i TagSource) String() string

Jump to

Keyboard shortcuts

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