I have an image saved as static/images/example.jpg inside a module, but I found that the imageConfig can’t resolve it from a module, but the fileExists function does, not sure if should it be considered as a bug.
common/ - The common module.
static/
images/
example.jpg
main/ - The site imports the common module.
{{- warnf "%s: %v" $filepath (fileExists $filepath) }}
{{- if fileExists $filepath }}
{{- with imageConfig $filepath }}
{{- $naturalHeight = printf "%dpx" .Height }}
{{- $naturalWidth = printf "%dpx" .Width }}
{{- end }}
{{- end }}
WARN static/images/example.jpg: true
...executing "partials/images/image.html" at <imageConfig $filepath>: error calling imageConfig: open /home/razonyang/Projects/hugomods/site/main/static/images/example.jpg: no such file or directory
imageConfig currently reads in the project working dir (only) – which is a limitation/bug, and should be fixed, but these “file funcs” precedes Hugo’s image/resource API, which should have less surprises in this area. I welcome fixes to these, but it’s non-trivial to do without breaking stuff, which is probably why It’s not on my priority list. I’m a pretty active Hugo user myself, and it’s many years since I used imageConfig, fileExists etc.
I suggest that you mount/put the images that you need to know dimensions from inside /assets.