Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Latest commit

 

History

History
91 lines (67 loc) · 2.62 KB

README.md

File metadata and controls

91 lines (67 loc) · 2.62 KB

goexif2

License Godoc ReportCard Build

This Golang package provides decoding of basic exif and tiff encoded data. This project is a fork of rwcarlsen/goexif with many pull requests and patches integrated.

NOTICE

I'm not developing goexif2 any further. This project was a fork of rwcarlsen/goexif which development has continued since then. The projects have been diverged and I will keep this for people using it in their applications. For new applications you could consider using the original package or search for your package of choice using pkg.go.dev.

Installation

To install the exif extraction cli tool, in a terminal type:

go install github.com/xor-gate/goexif2/cmd/goexif2
goexif2 <file>.jpg

Functionality is split into two packages - "exif" and "tiff" The exif package depends on the tiff package.

go get github.com/xor-gate/goexif2/exif
go get github.com/xor-gate/goexif2/tiff

Example

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/xor-gate/goexif2/exif"
	"github.com/xor-gate/goexif2/mknote"
)

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

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

	// Optionally register camera makenote data parsing - currently Nikon and
	// Canon are supported.
	exif.RegisterParsers(mknote.All...)

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

	camModel, _ := x.Get(exif.Model) // normally, don't ignore errors!
	fmt.Println(camModel.StringVal())

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

	// Two convenience functions exist for date/time taken and GPS coords:
	tm, _ := x.DateTime()
	fmt.Println("Taken: ", tm)

	lat, long, _ := x.LatLong()
	fmt.Println("lat, long: ", lat, ", ", long)
}

License

2-Clause BSD