Skip to content
New issue

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

ExifIFDPointer decode failed when attempting to read EXIF data. #74

Open
FooSoft opened this issue Jul 6, 2019 · 4 comments
Open

ExifIFDPointer decode failed when attempting to read EXIF data. #74

FooSoft opened this issue Jul 6, 2019 · 4 comments

Comments

@FooSoft
Copy link

FooSoft commented Jul 6, 2019

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

@FooSoft
Copy link
Author

FooSoft commented Jul 6, 2019

I should add that this was taken on a Huawei Mate SE, and all pictures it saves have this problem.

@mrauh
Copy link

mrauh commented Aug 17, 2019

Same here with pictures of a Huawei P20. Here is the output of a sample picture created with ExifTool: https://pastebin.com/bWF8Nus5

@mrauh
Copy link

mrauh commented Aug 17, 2019

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...

@FooSoft
Copy link
Author

FooSoft commented Aug 17, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants