exif

package
v0.0.0-...-8462f15 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2014 License: Apache-2.0, BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package exif implements decoding of EXIF data as defined in the EXIF 2.2 specification.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exif

type Exif struct {
	// contains filtered or unexported fields
}

func Decode

func Decode(r io.Reader) (*Exif, error)

Decode parses EXIF-encoded data from r and returns a queryable Exif object.

Example
package main

import (
	"fmt"
	"log"
	"os"

	"camlistore.org/third_party/github.com/camlistore/goexif/exif"
)

func main() {
	fname := "sample1.jpg"

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}

	x, err := exif.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	camModel, _ := x.Get("Model")
	date, _ := x.Get("DateTimeOriginal")
	fmt.Println(camModel.StringVal())
	fmt.Println(date.StringVal())

	focal, _ := x.Get("FocalLength")
	numer, denom := focal.Rat2(0) // retrieve first (only) rat. value
	fmt.Printf("%v/%v", numer, denom)
}
Output:

func (*Exif) DateTime

func (x *Exif) DateTime() (time.Time, error)

DateTime returns the EXIF's "DateTimeOriginal" field, which is the creation time of the photo. If not found, it tries the "DateTime" (which is meant as the modtime) instead. The error will be TagNotPresentErr if none of those tags were found, or a generic error if the tag value was not a string, or the error returned by time.Parse.

func (*Exif) Get

func (x *Exif) Get(name FieldName) (*tiff.Tag, error)

Get retrieves the EXIF tag for the given field name.

If the tag is not known or not present, an error is returned. If the tag name is known, the error will be a TagNotPresentError.

func (Exif) MarshalJSON

func (x Exif) MarshalJSON() ([]byte, error)

func (*Exif) String

func (x *Exif) String() string

String returns a pretty text representation of the decoded exif data.

func (*Exif) Walk

func (x *Exif) Walk(w Walker) error

Walk calls the Walk method of w with the name and tag for every non-nil exif field.

type FieldName

type FieldName string
const (
	ImageWidth       FieldName = "ImageWidth"
	ImageLength      FieldName = "ImageLength" // height
	Orientation      FieldName = "Orientation"
	DateTime         FieldName = "DateTime"
	DateTimeOriginal FieldName = "DateTimeOriginal"
)

type TagNotPresentError

type TagNotPresentError FieldName

A TagNotPresentError is returned when the requested field is not present in the EXIF.

func (TagNotPresentError) Error

func (tag TagNotPresentError) Error() string

type Walker

type Walker interface {
	Walk(name FieldName, tag *tiff.Tag) error
}

Walker is the interface used to traverse all exif fields of an Exif object. Returning a non-nil error aborts the walk/traversal.

Jump to

Keyboard shortcuts

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