Created
November 6, 2018 20:23
-
-
Save oldpatricka/f4137738a56c85e9c70f1ac88e3e3e30 to your computer and use it in GitHub Desktop.
Simple program to dump TIFF metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// To run, first install github.com/google/tiff with: | |
// go get github.com/google/tiff | |
// Then run like `go run tiff-dump.go example.tif` | |
import ( | |
"fmt" | |
"github.com/google/tiff" | |
"os" | |
) | |
func main() { | |
tiffFile := os.Args[1] | |
r, err := os.Open(tiffFile) | |
if err != nil { | |
panic(err) | |
} | |
tiff.SetTiffFieldPrintFullFieldValue(true) | |
t, err := tiff.Parse(r, nil, nil) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Version: %d\n", t.Version()) | |
fmt.Printf("Byte Order: %s\n\n", EndianString(t.Order())) | |
for i, ifd := range t.IFDs() { | |
fmt.Printf("IFD %d:\n", i) | |
for _, f := range ifd.Fields() { | |
fmt.Printf("%s\n", f) | |
} | |
} | |
} | |
func EndianString(magicEndian string) string { | |
if magicEndian == tiff.MagicBigEndian { | |
return "big endian" | |
} else { | |
return "little endian" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment