Exif failed to find exif intro marker in {{with .Exif}}

Following the documentation, I have a partial with a code block like this

{{ with .image }}
{{ with .Exif }}

So image should be defined in the outer with as should be .Exif in the inner with. However, I get this error message

execute of template failed: template: partials/gallery.html:31:19: executing "partials/gallery.html" at <$myimg.Exif>: error calling Exif: metadata init failed: exif: failed to find exif intro marker

when Hugo is trying to process one particular image. Although it is a JPEG, it seems to in fact not contain EXIF data (checked with exiftool and GraphicsConverter). Shouldn’t the with .Exif prevent a failure in exactly such a situation?
BTW: adding a single exif tag to the image with exiftool keeps Hugo happy.

BTW: adding a single exif tag to the image with exiftool keeps Hugo happy.

EXIF is basically some bits and bytes added to an image in binary after/before the actual data for the image and many systems are “OK” with “wrong” information in those areas. I remember having a “digital camera” from CANON 15 years ago that wrote idiotic EXIF information. I had to open the images in a graphic program and save them (without doing anything to them) and ONLY THEN the EXIF information was readable. I think with samples (images) that break the with you would have a good use case for an issue in the gohugoio repo. It’s probably an issue in a library upstream that does not expect weird formattings.

Maybe you can work around the error with an {{ if isset . "Exif"}}{{ with .Exif }} and two ends.

Thanks for the suggestion. I can try the if issetthingy, but the error also happens with other images that do have exif sections. The images in question are about four years old and from fairly recent cameras or iPhones, so I suppose the exif data is not completely bogus :wink:

If I understand you correctly, you are suggesting that I file an issue in github?

Yes. Issues · gohugoio/hugo · GitHub

I’m afraid it is more complicated than I thought.
First, isset $image "Exif" gives me a Hugo warning: calling IsSet with unsupported type "ptr" (*resources.resourceAdapter) will always return false. So that effectively stops all Exif processing.
Second, when I said

I was probably mislead. The shortcode in question processes all image resources in a page bundle. I have a warnf print the Permalink just before the with .Exif statement, so I know (hopefully) which image causes the problem. I can see Hugo processing images 1 through n and failing with this last one in the bundle. I move it out of the bundle and restart Hugo, which now fails with image n-1 – one that was perfectly ok just a minute before. This happens in a bundle with 71 images to use the Exif data of but about 280 images in total.
Third, with the “always false” isset in place, everything works ok, since the Exif stuff is never even touched.

I suspect your issue would be resolved more quickly if you shared (a) the image, and (b) the complete code used to process the image.

Here’s the code

{{$context := .context}}
{{ $id := .id}}
{{ $counter := 0}}
{{ $images := default ($context.Resources.ByType "image") .images }}
<div class="gallery" id="{{$id}}" itemscope itemtype="">
  {{ $imageArr := slice}}
  {{ range $images }}
  {{if not (in .Name "px" ) }}
  {{$imageArr = $imageArr | append (dict "image" . "ratio" (div .Height .Width))}}
  {{range sort $imageArr "ratio" "desc" }}
  {{with .image}}
    <figure itemscope itemtype="" class="image gallery-item">
      <a href="{{ .Permalink }}" itemprop="contentUrl"
      data-size="{{ .Width }}x{{ .Height }}" 
         data-sub-html="{{printf "#figcaption-%s-%d" $id $counter}}">
        {{ $ext := path.Ext .Permalink }}
        {{ $base := replace .Permalink $ext ""}}
        {{- $thumburl := replace .Permalink $base (printf "%s-300px" $base ) -}}
          {{partial "source.html" $thumburl}}
        <img itemprop="thumbnail" alt="galleryImage" class="galleryImage"
          src="{{ $thumburl}}" 
      {{warnf "%s" .Permalink}}
      <figcaption itemprop="caption description" 
      id="{{printf "figcaption-%s-%d" $id $counter}}">

      {{with .Exif}}
        {{if .Tags.ImageDescription }}
          {{warnf "Title: %s" .Tags.ImageDescription}}
      {{end }}
  {{ $counter = add $counter 1}}
  {{ end }}

And the image. Though I suppose that it is not really the culprit here: If I remove it from the bundle, the error occurs after warnf printed the URL of the image just before this one. What I find weird is that there’s a notable delay between the output of the warnf line and the error message. Even weirder: If I move the whole page bundle out of the way, the error happens again.

Please show the code where you call the partial.

That’s my single.html template:

{{ define "main" }}

<div class="container">
  <section class="section">
    <div class="columns ">
      <div class="column is-three-quarters max-800px">
          <h1 class="title is-2">{{ .Title }}</h1>
          <div class="content">
            {{ .Content }}
          {{ partial "gallery.html" (dict "context" . "id" "gallery") }}
      {{ partial "sidebar.html" .}}
{{ end }}

I’m unable to reproduce the problem with the information you have provided. Please share the entire repository, privately if you wish.

Being a complete Github noob, I’ve created a private repository here
If that’s not suitable, please let me know, then I’ll simply re-create it publicly. I do not seem to have a way to change the visibility.

Your repository is private. You need to make it public.

Now it’s public…

git clone
cd unterwegs

No errors…

Start building sites … 

                   |  EN   
  Pages            |    6  
  Paginator pages  |    0  
  Non-page files   |    0  
  Static files     | 1941  
  Processed images |    0  
  Aliases          |    0  
  Sitemaps         |    1  
  Cleaned          |    0  

Total in 310 ms

Uh, where’s your content directory?

Sorry. This is all very new for me. content is there now. However, the version of
themes/unterwegs/layouts/partials/gallery.html that’s in the repository has the Exif stuff commented out (because I wanted to get somewhere in the meantime ;-). Instead of

{{/* with .Exif */}}
        {{/* if .Tags.ImageDescription */}}
          {{/*warnf "Title: %s" .Tags.ImageDescription */}}
        {{/*end */}}
      {{/* end */}}

it should be

{{ with .Exif }}
        {{ if .Tags.ImageDescription }}
        {{end }}
      {{/end }}

That is just above <f/igcaption>

Start building sites … 
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "photos/Streetart/kuba": "/home/jmooring/temp/unterwegs/content/blog/Kuba bunt und sozialistisch/": page not found
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "/photos/Streetart/istanbul": "/home/jmooring/temp/unterwegs/content/blog/Nackte Ananas in Istanbul/": page not found
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "Schwitzend auf den Plätzen von Guangzhou": "/home/jmooring/temp/unterwegs/content/blog/Metropolis Shanghai, Kleinstadt Shanghai/": page not found
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "/photos/Streetart/esteli": "/home/jmooring/temp/unterwegs/content/blog/Nicaragua für Touristen Stadt und Land/": page not found
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "/photos/Streetart/ayvalik": "/home/jmooring/temp/unterwegs/content/blog/Schlachtfeld- und andere Touristen in Çanakkale/": page not found
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "/photos/Streetart/sofia": "/home/jmooring/temp/unterwegs/content/blog/Sofia Geschichte mit Lücken/": page not found
ERROR 2021/05/04 08:37:14 [en] REF_NOT_FOUND: Ref "Bei Kunming erholt man sich im Dunkeln und im Hellen": "/home/jmooring/temp/unterwegs/content/blog/Triest sehen und weiterleben/": page not found
Total in 1997 ms
Error: Error building site: logged 7 error(s)

These errors are caused by trying to link to draft content.

Ok, I’m always running hugo server -D, so I don’t see these errors.

Understood. I’ve found the problem, and I know how to fix it. I’m trying to find a way to make it easy for you to fix it.

Every image in content/photos/Streetart/ayvalik has metadata problems. Run these commands from the root of your project:

# Step 1: Extract content of Headline tag from every image.
exiftool -csv -Headline content/photos/Streetart/ayvalik > headlines.csv

# Step 2: Remove the Headline tag from every image.
exiftool -Headline= -overwrite_original content/photos/Streetart/ayvalik

# Step 3: Set the Headline tag for every image using the CSV file created in Step 1.
exiftool -csv=headlines.csv -overwrite_original content/photos/Streetart/ayvalik

# Step 4: Remove the CSV file.
rm headlines.csv