Image processing output image URLs change

Hi Hugo Peoples-

Is there a way to guarantee that the image output filenames for image processed images is always the same? For example, if I call this:
{{ $thumbnail := $image.Fill "800x450 Center" }}
and the output filename is this:
thumbnail_hue9118bbc5fb5fb16fd71fab5a793b94f_121525_800x450_fill_box_center_3.png

is there a way to guarantee that the filename will not change? Looking at that GUID, I’m guessing the answer is a resounding “no.”

See, I’m in a bit of a pickle. Someone in my organization has copied the URLs to said processed images and pasted them into html formatted e-mails. Since that time, we’ve updated hugo and made various changes. It looks like the filename convention - not to mention the GUID - has changed, breaking the image links. Since the e-mails have already gone out, the damage is done. Short of recreating those exact filenames manually, I’m not sure how best to fix this.

The resulting file name is a combination of the filename, an image hash, and the processing parameters.

The file name will change if:

  • You rename the original file
  • You replace the original file with a different image of the same name
  • You change processing parameters
  • A new version of Hugo bumps its internal API number if the underlying image processing changes (e.g., new version of a decoder/encoder)

This scheme prevents users from seeing the wrong image due to caching.

You can bypass this by using the resources.Copy function.

For a page resource that might look something like this:

{{ with .Resources.Get "a.jpg" }}
  {{ with .Resize "200x" }}
    {{ with . | resources.Copy (path.Join $.Page.RelPermalink .Name ) }}
      <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
    {{ end }}
  {{ end }}
{{ end }}

Thanks for the explanation and swift reply Joe! That makes sense.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.