Filename mismatch after image resize


I am resizing images and have a interesting issue in one blog entry.
After building on Windows (including image resizing), the filename and the RelPermalink differ in case and the file is therefore not visible on the Linux webserver.

Here the code:

{{ $path := print "content\\" .Page.File.Dir }}
{{ $url  := print .Page.File.Dir }}
<!-- <p>path={{$path}}</p> -->
<!-- <p>url={{$url}}</p> -->

{{ $images := .Page.Resources.ByType "image" }}
{{ range $images }}
    {{ $filepath := path.Join $path .}}
    {{ if fileExists $filepath }}
        {{ if gt (imageConfig $filepath).Width 800 -}}
            {{ $resized := .Resize "800x Lanczos" }}
            <source srcset="{{ $resized.RelPermalink }}">
            <img src="{{ $resized.RelPermalink }}">
        {{ else }}
            <source srcset="{{ .RelPermalink }}">
            <img src="{{ .RelPermalink }}">
        {{- end}}
    {{- end}}
{{ end }}

Original Filename: 02-IMG_8065.jpg
Resized Filename: 02-img_8065_hu37039713a5059b37fa6b211a128db7d6_250268_800x0_resize_q75_lanczos.jpg
Referenced File:

            <source srcset="/blog/day20/02-IMG_8065_hu37039713a5059b37fa6b211a128db7d6_250268_800x0_resize_q75_lanczos.jpg">
            <img src="/blog/day20/02-IMG_8065_hu37039713a5059b37fa6b211a128db7d6_250268_800x0_resize_q75_lanczos.jpg">        

Does the Resize function allow additional parameters to cover the case issue?
How to deal with this? Rename everything lowercase upfront and rerun hugo build would be a workaround…

Thanks for your time & Kind regards

Hi again.

I used a workaround by building the page on WSL for Windows. There the filenames are identical on the filesystem and in the resulting HTML.


1 Like