Documentation ¶
Overview ¶
Package picinfo provides picture file information based on exif standard
Index ¶
- Variables
- func AddExifPrefix(exifData []byte) []byte
- func DecDegFromDMS(degs, mins, secs float64) float64
- func EntryToFloat(e *exif.ExifTag) float64
- func EntryToFloats(e *exif.ExifTag) []float64
- func EntryToInt(e *exif.ExifTag) int
- func ExifDateParser(ds string) (time.Time, error)
- func OpenBytes(fn string) ([]byte, error)
- func OpenHEIC(fname string) (image.Image, error)
- func OpenImage(fname string) (image.Image, error)
- func OpenImageAuto(fname string) (image.Image, error)
- func OpenRawExif(fn string) ([]byte, error)
- func OrientImage(img image.Image, orient Orientations) image.Image
- func SaveImage(fname string, im image.Image) error
- type Exposure
- type GPSCoord
- type GPSMisc
- type IfdEntry
- type Info
- func (pi *Info) Defaults()
- func (pi *Info) DiffsTo(npi *Info) []string
- func (pi *Info) FileBase() string
- func (pi *Info) GetSize() image.Point
- func (pi *Info) GetSizeOrient() image.Point
- func (pi *Info) ImageOriented() (image.Image, error)
- func (pi *Info) ParseRawExif(rawExif []byte)
- func (pi *Info) SaveJpegExif(rawExif []byte, img image.Image) error
- func (pi *Info) SaveJpegNew(img image.Image) error
- func (pi *Info) SaveJpegUpdated() error
- func (pi *Info) SaveJpegUpdatedExif(rawExif []byte, img image.Image) error
- func (pi *Info) SaveJpegUpdatedFailsafe() error
- func (pi *Info) SetFileThumbFmBase(fnext, fdir, tdir string)
- func (pi *Info) SetFileThumbFmFile(fname, tdir string)
- func (pi *Info) UpdateExif(rawExif []byte, rootIfd *exif.Ifd) (ib *exif.IfdBuilder, updt bool, err error)
- func (pi *Info) UpdateFileMod() error
- type Orientations
- func (i *Orientations) FromString(s string) error
- func (ev Orientations) MarshalJSON() ([]byte, error)
- func (or Orientations) OrientSize(sz image.Point) image.Point
- func (or Orientations) Rotate(deg int) Orientations
- func (i Orientations) String() string
- func (ev *Orientations) UnmarshalJSON(b []byte) error
- type PicMap
- type Pics
Constants ¶
This section is empty.
Variables ¶
var JpegEncodeQuality = 90
JpegEncodeQuality is the default encoding quality for Jpeg files
var KiT_Orientations = kit.Enums.AddEnum(OrientationsN, kit.NotBitFlag, nil)
Functions ¶
func AddExifPrefix ¶
AddExifPrefix adds the standard Exif00 prefix to given encoded exif data if not already present
func DecDegFromDMS ¶
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 OpenImage ¶
OpenImage opens an image from given filename. Supports: png, jpeg, tiff, gif, bmp, pgm, pbm, ppm, pnm, and heic formats.
func OpenImageAuto ¶
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 ¶
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
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 ¶
NewInfoForFile returns a new Info initialized with basic info from file
func OpenNewInfo ¶
OpenNewInfo opens file and reads the exif info for given file, returning a new Info with that info all set.
func (*Info) GetSize ¶
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 ¶
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 ¶
ImageOriented returns the opened image for this file, oriented according to the Orient setting. errors are logged.
func (*Info) ParseRawExif ¶
ParseRawExif parses the raw Exif data into our Info structure
func (*Info) SaveJpegExif ¶
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 ¶
SaveJpegNew saves a new Jpeg encoded file with exif data generated from current info
func (*Info) SaveJpegUpdated ¶
SaveJpegUpdated saves a new Jpeg encoded file with info updated to reflect given info
func (*Info) SaveJpegUpdatedExif ¶
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 ¶
SaveJpegUpdatedFailsafe is a more robust version of jpeg updating when jpegstructure fails
func (*Info) SetFileThumbFmBase ¶
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 ¶
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 ¶
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 ¶
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 ¶
InfoByName returns the Info record based on file name (strips extension)
func (*PicMap) SetFileThumb ¶
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) IdxByThumb ¶
IdxByThumb returns the index of given Thumb name
func (Pics) SortByDate ¶
SortByDate sorts the pictures by date taken