2012-11-19 22:04:04 +00:00
|
|
|
goexif
|
|
|
|
======
|
|
|
|
|
|
|
|
Provides decoding of basic exif and tiff encoded data. Still in alpha - no guarantees.
|
|
|
|
Suggestions and pull requests are welcome. Functionality is split into two packages - "exif" and "tiff"
|
|
|
|
The exif package depends on the tiff package.
|
2014-09-03 20:47:24 +00:00
|
|
|
Documentation can be found at http://godoc.org/github.com/rwcarlsen/goexif
|
|
|
|
|
|
|
|
Like goexif? - Bitcoin tips welcome: 17w65FVqx196Qp7tfCCSLqyvsHUhiEEa7P
|
2012-11-19 22:04:04 +00:00
|
|
|
|
|
|
|
To install, in a terminal type:
|
|
|
|
|
|
|
|
```
|
2014-09-03 20:47:24 +00:00
|
|
|
go get github.com/rwcarlsen/goexif/exif
|
2012-11-19 22:04:04 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Or if you just want the tiff package:
|
|
|
|
|
|
|
|
```
|
2014-09-03 20:47:24 +00:00
|
|
|
go get github.com/rwcarlsen/goexif/tiff
|
2012-11-19 22:04:04 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-08-28 13:29:30 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2012-11-19 22:04:04 +00:00
|
|
|
|
2014-08-28 13:29:30 +00:00
|
|
|
"github.com/rwcarlsen/goexif/exif"
|
|
|
|
"github.com/rwcarlsen/goexif/mknote"
|
2012-11-19 22:04:04 +00:00
|
|
|
)
|
|
|
|
|
2014-08-28 13:29:30 +00:00
|
|
|
func ExampleDecode() {
|
2014-09-03 20:47:24 +00:00
|
|
|
fname := "sample1.jpg"
|
|
|
|
|
|
|
|
f, err := os.Open(fname)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:29:30 +00:00
|
|
|
// Optionally register camera makenote data parsing - currently Nikon and
|
|
|
|
// Canon are supported.
|
|
|
|
exif.RegisterParsers(mknote.All...)
|
|
|
|
|
2014-09-03 20:47:24 +00:00
|
|
|
x, err := exif.Decode(f)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:29:30 +00:00
|
|
|
camModel, _ := x.Get(exif.Model) // normally, don't ignore errors!
|
2014-09-03 20:47:24 +00:00
|
|
|
fmt.Println(camModel.StringVal())
|
|
|
|
|
|
|
|
focal, _ := x.Get(exif.FocalLength)
|
2014-08-28 13:29:30 +00:00
|
|
|
numer, denom, _ := focal.Rat2(0) // retrieve first (only) rat. value
|
2014-09-03 20:47:24 +00:00
|
|
|
fmt.Printf("%v/%v", numer, denom)
|
2014-08-28 13:29:30 +00:00
|
|
|
|
|
|
|
// 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)
|
2012-11-19 22:04:04 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
<!--golang-->
|
2013-10-10 05:00:24 +00:00
|
|
|
[](http://githalytics.com/rwcarlsen/goexif)
|