mirror of https://github.com/dsoprea/go-exif.git
ifd: Can now resolve its own tags' values.
- Adjustments to argument naming.pull/3/head
parent
98b3d60a12
commit
cf17cf4aa6
|
@ -26,8 +26,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
filepathArgument = ""
|
filepathArg = ""
|
||||||
printAsJsonArgument = false
|
printAsJsonArg = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,17 +52,17 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
flag.StringVar(&filepathArgument, "filepath", "", "File-path of image")
|
flag.StringVar(&filepathArg, "filepath", "", "File-path of image")
|
||||||
flag.BoolVar(&printAsJsonArgument, "json", false, "Print JSON")
|
flag.BoolVar(&printAsJsonArg, "json", false, "Print JSON")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if filepathArgument == "" {
|
if filepathArg == "" {
|
||||||
fmt.Printf("Please provide a file-path for an image.\n")
|
fmt.Printf("Please provide a file-path for an image.\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(filepathArgument)
|
f, err := os.Open(filepathArg)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(f)
|
data, err := ioutil.ReadAll(f)
|
||||||
|
@ -146,7 +146,7 @@ func main() {
|
||||||
_, err = e.Visit(data[foundAt:], visitor)
|
_, err = e.Visit(data[foundAt:], visitor)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
if printAsJsonArgument == true {
|
if printAsJsonArg == true {
|
||||||
data, err := json.MarshalIndent(entries, "", " ")
|
data, err := json.MarshalIndent(entries, "", " ")
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,11 @@ func (ie *IfdEnumerate) Scan(ifdOffset uint32, visitor TagVisitor) (err error) {
|
||||||
|
|
||||||
|
|
||||||
type Ifd struct {
|
type Ifd struct {
|
||||||
|
// This is just for convenience, just so that we can easily get the values
|
||||||
|
// and not involve other projects in semantics that they won't otherwise
|
||||||
|
// need to know.
|
||||||
|
addressableData []byte
|
||||||
|
|
||||||
ByteOrder binary.ByteOrder
|
ByteOrder binary.ByteOrder
|
||||||
|
|
||||||
Ii IfdIdentity
|
Ii IfdIdentity
|
||||||
|
@ -289,6 +294,19 @@ type Ifd struct {
|
||||||
NextIfd *Ifd
|
NextIfd *Ifd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ifd *Ifd) TagValue(ite *IfdTagEntry) (value interface{}, err error) {
|
||||||
|
defer func() {
|
||||||
|
if state := recover(); state != nil {
|
||||||
|
err = log.Wrap(state.(error))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
value, err = ite.Value(ifd.addressableData, ifd.ByteOrder)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FindTagWithId returns a list of tags (usually just zero or one) that match
|
// FindTagWithId returns a list of tags (usually just zero or one) that match
|
||||||
// the given tag ID. This is efficient.
|
// the given tag ID. This is efficient.
|
||||||
func (ifd Ifd) FindTagWithId(tagId uint16) (results []*IfdTagEntry, err error) {
|
func (ifd Ifd) FindTagWithId(tagId uint16) (results []*IfdTagEntry, err error) {
|
||||||
|
@ -550,6 +568,8 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error
|
||||||
}
|
}
|
||||||
|
|
||||||
ifd := Ifd{
|
ifd := Ifd{
|
||||||
|
addressableData: ie.exifData[ExifAddressableAreaStart:],
|
||||||
|
|
||||||
ByteOrder: ie.byteOrder,
|
ByteOrder: ie.byteOrder,
|
||||||
Ii: ii,
|
Ii: ii,
|
||||||
Id: id,
|
Id: id,
|
||||||
|
|
Loading…
Reference in New Issue