We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempting to extract GPS metadata from an image known to contain it causes the following error to be logged:
loading EXIF sub-IFD: exif: sub-IFD ExifIFDPointer decode failed: zero length tag value
Go version:
go version go1.12.6 linux/amd64
Test code (basically copy-paste of sample):
package main import ( "fmt" "log" "os" "github.com/rwcarlsen/goexif/exif" "github.com/rwcarlsen/goexif/mknote" ) func main() { fname := "osaka.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) }
Image file: https://github.com/FooSoft/goldsmith-components/raw/master/plugins/exif/testdata/source/osaka.jpg
The text was updated successfully, but these errors were encountered:
I should add that this was taken on a Huawei Mate SE, and all pictures it saves have this problem.
Sorry, something went wrong.
Same here with pictures of a Huawei P20. Here is the output of a sample picture created with ExifTool: https://pastebin.com/bWF8Nus5
I was able to solve my problem by ignoring non-critical decoding errors and using DateTime() instead of Get(exif.DateTimeOriginal).
@FooSoft As you are trying to extract GPS metadata, maybe the LatLong() function works for you.
Here is my snippet that finally works:
x, err := exif.Decode(f) if err != nil { if exif.IsCriticalError(err) { return nil, err } } defer f.Close() dt, err := x.DateTime() if err != nil { return nil, err } // Use dt...
@mrauh thanks for the example, I did not realize IsCriticalError was something that I should be looking for; does not appear to be very intuitive.
IsCriticalError
No branches or pull requests
Attempting to extract GPS metadata from an image known to contain it causes the following error to be logged:
Go version:
Test code (basically copy-paste of sample):
Image file: https://github.com/FooSoft/goldsmith-components/raw/master/plugins/exif/testdata/source/osaka.jpg
The text was updated successfully, but these errors were encountered: