Repository: gohugoio/hugo (language: go)

Issue:
`error calling Exif: metadata init failed: json: unsupported value: NaN`
<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.111.3+extended linux/arm BuildDate=2023-03-16T08:41:31Z VendorInfo=raspbian:0.111.3-1
</pre>

### Does this issue reproduce with the latest release?
i'm not sure, but seems likely given https://github.com/gohugoio/hugo/issues/8996 and https://github.com/gohugoio/hugo/issues/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.


Discussion / hints:
Can you share the original image?
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](https://github.com/gohugoio/hugo/assets/231498/0411f27c-c56d-4b4c-b5fa-b5c0e74cc990)

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.
There appears to be something wrong with the GPSInfo:


```text
$ 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...

```text
$ 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.


Correction: if you're willing to live without GPS data on all of your photos, you can do this in your site configuration:

```text
[imaging.exif]
disableLatLong = true
```
I've tested this, and we can fix by changing this:

<https://github.com/gohugoio/hugo/blob/ee26e69ce3367ebfe1e35f03695d51b049aab955/resources/images/exif/exif.go#L141-L143>

To this:

```go
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:

```text
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
```

Fix patch:
diff --git a/resources/images/exif/exif.go b/resources/images/exif/exif.go
index af92366cacd..0374cdc961b 100644
--- a/resources/images/exif/exif.go
+++ b/resources/images/exif/exif.go
@@ -17,6 +17,7 @@ import (
 	"bytes"
 	"fmt"
 	"io"
+	"math"
 	"math/big"
 	"regexp"
 	"strings"
@@ -140,6 +141,12 @@ func (d *Decoder) Decode(r io.Reader) (ex *ExifInfo, err error) {
 
 	if !d.noLatLong {
 		lat, long, _ = x.LatLong()
+		if math.IsNaN(lat) {
+			lat = 0
+		}
+		if math.IsNaN(long) {
+			long = 0
+		}
 	}
 
 	walker := &exifWalker{x: x, vals: make(map[string]any), includeMatcher: d.includeFieldsRe, excludeMatcher: d.excludeFieldsrRe}


Test patch: