picinfo

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Overview

Package picinfo provides picture file information based on exif standard

Index

Constants

This section is empty.

Variables

View Source
var JpegEncodeQuality = 90

JpegEncodeQuality is the default encoding quality for Jpeg files

View Source
var KiT_Orientations = kit.Enums.AddEnum(OrientationsN, kit.NotBitFlag, nil)

Functions

func AddExifPrefix

func AddExifPrefix(exifData []byte) []byte

AddExifPrefix adds the standard Exif00 prefix to given encoded exif data if not already present

func DecDegFromDMS

func DecDegFromDMS(degs, mins, secs float64) float64

DecDegFromDMS converts from degrees, minutes and seconds to a decimal

func EntryToFloat

func EntryToFloat(e *exif.ExifTag) float64

func EntryToFloats

func EntryToFloats(e *exif.ExifTag) []float64

func EntryToInt

func EntryToInt(e *exif.ExifTag) int

func ExifDateParser

func ExifDateParser(ds string) (time.Time, error)

func OpenBytes

func OpenBytes(fn string) ([]byte, error)

OpenBytes opens file and returns bytes

func OpenHEIC

func OpenHEIC(fname string) (image.Image, error)

OpenHEIC opens a HEIC formatted file

func OpenImage

func OpenImage(fname string) (image.Image, error)

OpenImage opens an image from given filename. Supports: png, jpeg, tiff, gif, bmp, pgm, pbm, ppm, pnm, and heic formats.

func OpenImageAuto

func OpenImageAuto(fname string) (image.Image, error)

OpenImageAuto opens an image from given filename. Format is inferred automatically, using image package decoders registered. Supports: png, jpeg, tiff, gif, bmp, pgm, pbm, ppm, pnm formats.

func OpenRawExif

func OpenRawExif(fn string) ([]byte, error)

OpenRawExif opens the raw exif data bytes from given file. This is very crude and must parse and re-generate the exif before re-saving to another file.

func OrientImage

func OrientImage(img image.Image, orient Orientations) image.Image

OrientImage returns an image with the proper orientation as specified

func SaveImage

func SaveImage(fname string, im image.Image) error

SaveImage saves image to file, with format inferred from filename. Supports: png, jpeg, tiff, gif, bmp, pgm, pbm, ppm, pnm formats. Uses standard default options -- use encoder for other options.

Types

type Exposure

type Exposure struct {

	// exposure time
	Time float64 `desc:"exposure time"`

	// fstop
	FStop float64 `desc:"fstop"`

	// ISO speed
	ISOSpeed float64 `desc:"ISO speed"`

	// focal length
	FocalLen float64 `desc:"focal length"`

	// aperture
	Aperture float64 `desc:"aperture"`
}

Exposure has standard exposure information

type GPSCoord

type GPSCoord struct {

	// latitutde as decimal degrees -- a single value in range +/-90.etc
	Lat float64 `desc:"latitutde as decimal degrees -- a single value in range +/-90.etc"`

	// longitude as decimal degrees -- a single value in range +/-180.etc
	Long float64 `desc:"longitude as decimal degrees -- a single value in range +/-180.etc"`

	// altitude in meters
	Alt float64 `desc:"altitude in meters"`
}

GPSCoord is a GPS position as decimal degrees

type GPSMisc

type GPSMisc struct {

	// destination bearing -- where is the phone going
	DestBearing float64 `desc:"destination bearing -- where is the phone going"`

	// reference for bearing:  M = magnetic, T = true north
	DestBearingRef string `desc:"reference for bearing:  M = magnetic, T = true north"`

	// image direction -- where the phone is pointing
	ImgDir float64 `desc:"image direction -- where the phone is pointing"`

	// reference for image direction: M = magnetic, T = true north
	ImgDirRef string `desc:"reference for image direction: M = magnetic, T = true north"`

	// camera speed
	Speed float64 `desc:"camera speed"`

	// camera speed reference: K = Km/hr, M = MPH, N = knots
	SpeedRef string `desc:"camera speed reference: K = Km/hr, M = MPH, N = knots"`
}

GPSMisc is GPS bearing and other extra data

type IfdEntry

type IfdEntry struct {
	IfdPath     string                      `json:"ifd_path"`
	FqIfdPath   string                      `json:"fq_ifd_path"`
	IfdIndex    int                         `json:"ifd_index"`
	TagId       uint16                      `json:"tag_id"`
	TagName     string                      `json:"tag_name"`
	TagTypeId   exifcommon.TagTypePrimitive `json:"tag_type_id"`
	TagTypeName string                      `json:"tag_type_name"`
	UnitCount   uint32                      `json:"unit_count"`
	Value       any                         `json:"value"`
	ValueString string                      `json:"value_string"`
}

One entry of EXIF data -- used internally

type Info

type Info struct {

	// full path to image file name
	File string `json:"-" desc:"full path to image file name"`

	// extension of the file name
	Ext string `desc:"extension of the file name"`

	// image description -- can contain arbitrary user comments -- ascii encoded
	Desc string `desc:"image description -- can contain arbitrary user comments -- ascii encoded"`

	// date when image file was modified
	FileMod time.Time `desc:"date when image file was modified"`

	// supported type of image file, decoded from extension, using gopi/filecat system
	Sup filecat.Supported `desc:"supported type of image file, decoded from extension, using gopi/filecat system"`

	// if there are multiple files taken at the same time, e.g., in a Burst, this is the number
	Number int `desc:"if there are multiple files taken at the same time, e.g., in a Burst, this is the number"`

	// size of image in raw pixels
	Size image.Point `desc:"size of image in raw pixels"`

	// number of bits in each color component (e.g., 8 is typical)
	Depth int `desc:"number of bits in each color component (e.g., 8 is typical)"`

	// orientation of the image using exif standards that include rotation and mirroring
	Orient Orientations `desc:"orientation of the image using exif standards that include rotation and mirroring"`

	// date when the image / video was taken
	DateTaken time.Time `desc:"date when the image / video was taken"`

	// date when image was last modified / edited
	DateMod time.Time `desc:"date when image was last modified / edited"`

	// [view: inline] GPS coordinates of location of shot
	GPSLoc GPSCoord `view:"inline" desc:"GPS coordinates of location of shot"`

	// GPS misc additional data
	GPSMisc GPSMisc `desc:"GPS misc additional data"`

	// GPS version of the time
	GPSDate time.Time `desc:"GPS version of the time"`

	// standard exposure info
	Exposure Exposure `desc:"standard exposure info"`

	// full set of name / value tags
	Tags map[string]string `desc:"full set of name / value tags"`

	// [view: -] full path to thumb file name -- e.g., encoded as a .jpg
	Thumb string `json:"-" view:"-" desc:"full path to thumb file name -- e.g., encoded as a .jpg"`

	// [view: -] general-purpose flag state, e.g., for pruning old files
	Flagged bool `json:"-" view:"-" desc:"general-purpose flag state, e.g., for pruning old files"`
}

Info is the information about a picture / video file

func NewInfoForFile

func NewInfoForFile(fn string) (*Info, error)

NewInfoForFile returns a new Info initialized with basic info from file

func OpenNewInfo

func OpenNewInfo(fn string) (*Info, error)

OpenNewInfo opens file and reads the exif info for given file, returning a new Info with that info all set.

func (*Info) Defaults

func (pi *Info) Defaults()

func (*Info) DiffsTo

func (pi *Info) DiffsTo(npi *Info) []string

DiffsTo returns any differences between this and another Info record

func (*Info) FileBase

func (pi *Info) FileBase() string

FileBase returns the base, no extension file name (used as Key ic PicsMap)

func (*Info) GetSize

func (pi *Info) GetSize() image.Point

GetSize returns the "raw" size of the image, either from info value or directly from image -- this is the non-re-oriented size. In general it is a good idea to ensure that images have their sizes saved!

func (*Info) GetSizeOrient

func (pi *Info) GetSizeOrient() image.Point

GetSizeOrient is the size of the image after it is transformed by the Orientation i.e., the actual display size of the image.

func (*Info) ImageOriented

func (pi *Info) ImageOriented() (image.Image, error)

ImageOriented returns the opened image for this file, oriented according to the Orient setting. errors are logged.

func (*Info) ParseRawExif

func (pi *Info) ParseRawExif(rawExif []byte)

ParseRawExif parses the raw Exif data into our Info structure

func (*Info) SaveJpegExif

func (pi *Info) SaveJpegExif(rawExif []byte, img image.Image) error

SaveJpegExif saves a new Jpeg encoded file with given raw bytes of exif data Note: rawExif does NOT have to have the standard Exif00 prefix already -- will be added

func (*Info) SaveJpegNew

func (pi *Info) SaveJpegNew(img image.Image) error

SaveJpegNew saves a new Jpeg encoded file with exif data generated from current info

func (*Info) SaveJpegUpdated

func (pi *Info) SaveJpegUpdated() error

SaveJpegUpdated saves a new Jpeg encoded file with info updated to reflect given info

func (*Info) SaveJpegUpdatedExif

func (pi *Info) SaveJpegUpdatedExif(rawExif []byte, img image.Image) error

SaveJpegUpdatedExif saves a new Jpeg encoded file with given raw bytes of exif data, which is updated to current Info settings prior to saving.

func (*Info) SaveJpegUpdatedFailsafe

func (pi *Info) SaveJpegUpdatedFailsafe() error

SaveJpegUpdatedFailsafe is a more robust version of jpeg updating when jpegstructure fails

func (*Info) SetFileThumbFmBase

func (pi *Info) SetFileThumbFmBase(fnext, fdir, tdir string)

SetFileThumbFmBase sets the File and Thumb name based on given file *base* name (no extension) and File directory, Thumb directory. Ext must already have been set. This is useful for initializing after loading or renaming base name.

func (*Info) SetFileThumbFmFile

func (pi *Info) SetFileThumbFmFile(fname, tdir string)

SetFileThumbFmFile sets the File and Thumb name based on given full File path name and Thumb directory. Sets Ext. This is useful for creating new Info from file.

func (*Info) UpdateExif

func (pi *Info) UpdateExif(rawExif []byte, rootIfd *exif.Ifd) (ib *exif.IfdBuilder, updt bool, err error)

UpdateExif reads the exif from file, and generates a new exif incorporating changes from given Info. if rootIfd != nil it is used as a starting point otherwise it is generated from the rawExif, which also can be nil if starting fresh. returns true if data was different and requires saving.

func (*Info) UpdateFileMod

func (pi *Info) UpdateFileMod() error

UpdateFileMod updates the modification time on the file

type Orientations

type Orientations int

Orientations are the exif rotations and mirroring codes

const (
	// NoOrient means no orientation information was set -- assume Rotate0
	NoOrient Orientations = iota

	// Rotated0 means the image data is in the correct orientation as is
	Rotated0

	// FlippedH means the image is flipped in the horizontal axis
	FlippedH

	// Rotated180 means the image is rotated 180 degrees
	Rotated180

	// FlippedV means the image is flipped in the vertical axis
	FlippedV

	// FlippedHRotated90L means the image is flipped horizontally and rotated 90 degrees left
	FlippedHRotated90L

	// Rotated90L means the image is rotated 90 degrees to the left (counter-clockwise)
	Rotated90L

	// FlippedHRotated90R means the image is flipped horizontally and rotated 90 degrees right
	FlippedHRotated90R

	// Rotated90R means the image is rotated 90 degrees to the right (clockwise)
	Rotated90R

	// OrientUndef means undefined
	OrientUndef

	OrientationsN
)

func (*Orientations) FromString

func (i *Orientations) FromString(s string) error

func (Orientations) MarshalJSON

func (ev Orientations) MarshalJSON() ([]byte, error)

func (Orientations) OrientSize

func (or Orientations) OrientSize(sz image.Point) image.Point

OrientSize returns the size after image is oriented accordingly

func (Orientations) Rotate

func (or Orientations) Rotate(deg int) Orientations

Rotate returns orientation updated with given +/-90 or 180 degree rotation. In general, it goes the opposite of the name as that is what is done to compensate.

func (Orientations) String

func (i Orientations) String() string

func (*Orientations) UnmarshalJSON

func (ev *Orientations) UnmarshalJSON(b []byte) error

type PicMap

type PicMap map[string]*Info

PicMap is a map of Info for a collection of pictures, with the key being the file name *without extension*, so it can be used with thumb or picture filenames, and is consistent if the file extension is changed.

func (*PicMap) InfoByName

func (pm *PicMap) InfoByName(fname string) (*Info, bool)

InfoByName returns the Info record based on file name (strips extension)

func (*PicMap) OpenJSON

func (pm *PicMap) OpenJSON(fname string) error

OpenJSON opens from a JSON encoded file. Logs any errors.

func (*PicMap) SaveJSON

func (pm *PicMap) SaveJSON(fname string) error

SaveJSON saves to a JSON encoded file

func (*PicMap) Set

func (pm *PicMap) Set(pi *Info)

Set sets the Info into the map

func (*PicMap) SetFileThumb

func (pm *PicMap) SetFileThumb(adir, tdir string)

SetFileThumb sets the File and Thumb names based on given directories. These are not saved in the JSON files to conserve space. Thumb is always set to a .jpg version of base file name.

type Pics

type Pics []*Info

Pics is a slice of Info for a list of pictures

func (Pics) IdxByFile

func (pc Pics) IdxByFile(fname string) int

IdxByFile returns the index of given File name

func (Pics) IdxByThumb

func (pc Pics) IdxByThumb(tname string) int

IdxByThumb returns the index of given Thumb name

func (Pics) SortByDate

func (pc Pics) SortByDate(ascending bool)

SortByDate sorts the pictures by date taken

func (Pics) Thumbs

func (pc Pics) Thumbs() []string

Thumbs returns the list of thumbs for this set of pictures

Jump to

Keyboard shortcuts

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