-
-
Save oldpatricka/f655c5a754e10775955df7458ecc0c91 to your computer and use it in GitHub Desktop.
Basic tool to dump TIFF Headers
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
// dump-tiff.go - Basic tool to dump TIFF Headers | |
// | |
// depends on github.com/google/tiff, which you can install with: | |
// $ go get github.com/google/tiff | |
package main | |
import ( | |
"os" | |
"log" | |
"github.com/google/tiff" | |
_ "github.com/google/tiff/geotiff" | |
"fmt" | |
) | |
func main() { | |
if len(os.Args) != 2 { | |
fmt.Fprintf(os.Stderr, "usage: %s file.tif", os.Args[0]) | |
os.Exit(1) | |
} | |
filename := os.Args[1] | |
reader, err := os.Open(filename) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer reader.Close() | |
t, err := tiff.Parse(reader, nil, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("Dumping TIFF headers for %s:\n", filename) | |
PrintTiff(t) | |
PrintCOGInfo(t) | |
} | |
func PrintTiff(t tiff.TIFF) { | |
fmt.Printf("Version: %d\n", t.Version()) | |
fmt.Printf("Byte Order: %s\n", EndianString(t.Order())) | |
for i, ifd := range t.IFDs() { | |
fmt.Printf("IFD %d:\n", i) | |
for _, f := range ifd.Fields() { | |
PrintField(f) | |
} | |
} | |
} | |
func PrintCOGInfo(t tiff.TIFF) { | |
fmt.Println("\nTags for Cloud Optimized TIFFs:") | |
for i, ifd := range t.IFDs() { | |
fmt.Printf("IFD %d:\n", i) | |
for _, f := range ifd.Fields() { | |
tag := f.Tag() | |
if tag.Name() == "TileWidth" { | |
PrintField(f) | |
} | |
if tag.Name() == "TileOffsets" { | |
PrintField(f) | |
} | |
if tag.Name() == "TileByteCounts" { | |
PrintField(f) | |
} | |
} | |
} | |
} | |
func PrintField(f tiff.Field) { | |
tag := f.Tag() | |
fmt.Printf("Tag: ID: %d\tName: %s\tType: %s\n", tag.ID(), tag.Name(), f.Type().Name()) | |
} | |
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