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

error calling Exif: metadata init failed: json: unsupported value: NaN #12490

Closed
khimaros opened this issue May 13, 2024 · 7 comments · Fixed by #12492
Closed

error calling Exif: metadata init failed: json: unsupported value: NaN #12490

khimaros opened this issue May 13, 2024 · 7 comments · Fixed by #12492

Comments

@khimaros
Copy link

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.111.3+extended linux/arm BuildDate=2023-03-16T08:41:31Z VendorInfo=raspbian:0.111.3-1

Does this issue reproduce with the latest release?

i'm not sure, but seems likely given #8996 and #8586

description

this template results in failure on some images. it's difficult to determine which images are failing because

{{ range sort .Resources ".Name" "asc" }}
  <u>{{ .Name }}</u>
  {{ if eq .ResourceType "image" }}
    {{ $image := .Resize "1024x" }}
    <img src="{{ $image.RelPermalink }}" alt="{{ .Name }}"/>
    <div class="image-metadata">
      {{ .Exif }}
    </div>
  {{ end }}
{{ end }}

i was able to determine the specific image this is failing on and the data looks fine using the exif command line tool. all photos were all taken using Google Camera on a Pixel 6 phone.

is there a way to detect or somehow "catch" this error in my templates? it's fine if the data is blank for some images.

@khimaros khimaros changed the title error calling Ex if: metadata init failed: json: unsupported value: NaN error calling Exif: metadata init failed: json: unsupported value: NaN May 13, 2024
@jmooring
Copy link
Member

Can you share the original image?

@khimaros
Copy link
Author

i believe this is the one that is failing (added some warnf to the template and this is consistently the last one logged before failure)

failing image

@khimaros
Copy link
Author

when i move this image out of the way, it still fails on another. it seems like some images work, but quite a few fail.

@bep bep removed the NeedsTriage label May 13, 2024
@bep bep added this to the v0.126.0 milestone May 13, 2024
@jmooring
Copy link
Member

There appears to be something wrong with the GPSInfo:

$ exiftool assets/images/a.jpg | grep GPS

GPS Version ID                  : 0.0.0.0
GPS Latitude Ref                : Unknown ()
GPS Longitude Ref               : Unknown ()
GPS Altitude Ref                : Above Sea Level
GPS Time Stamp                  : 00:00:00
GPS Img Direction Ref           : Unknown ()
GPS Img Direction               : undef
GPS Date Stamp                  : 
GPS Date/Time                   :  00:00:00Z
GPS Latitude                    : 
GPS Longitude                   : 

This fixes it...

$ exiftool -GPSLatitude= assets/images/a.jpg

... but removing GPSLongitude fixes it as well, so maybe exiftool cleans up the whole GPSInfo block when updating any of its tags.

Other than updating the image, I don't know of a way around this in Hugo.

@jmooring
Copy link
Member

Correction: if you're willing to live without GPS data on all of your photos, you can do this in your site configuration:

[imaging.exif]
disableLatLong = true

@jmooring
Copy link
Member

jmooring commented May 13, 2024

I've tested this, and we can fix by changing this:

if !d.noLatLong {
lat, long, _ = x.LatLong()
}

To this:

if !d.noLatLong {
	lat, long, _ = x.LatLong()
	if math.IsNaN(lat) {
		lat = 0
	}
	if math.IsNaN(long) {
		long = 0
	}
}

It seems like setting the values to 0 is better than throwing an error that you can't work around unless you disable lat/long site wide.

Reproducible example:

git clone --single-branch -b hugo-github-issue-12490 https://github.com/jmooring/hugo-testing hugo-github-issue-12490
cd hugo-github-issue-12490
hugo server

Copy link

github-actions bot commented Jun 5, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants