-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imageConfig uses incorrect path for finding file #6763
Comments
A hacky workaround. Still seems to be broken in
|
I can confirm the issue, I've had to do something similar for images that are in my content directory. Paths that exist according to the function Here's my image render hook, for a website with hundreds of pictures in both /content/ and /static/: {{ $width := 0 }}
{{ $height := 0 }}
{{ $path := add .Page.RelPermalink (.Destination | safeURL) }}
{{ if not (fileExists $path) }}
{{ $path = printf "%s%s" "static" (.Destination | safeURL) }}
{{ end }}
{{ if (fileExists $path) }}
{{ $fullPath := $path }}
{{ if not (findRE "^static" $path 1) }}
{{ $fullPath = add "content" $fullPath }}
{{ end }}
{{ with (imageConfig $fullPath) }}
{{ $width = .Width }}
{{ $height = .Height }}
{{ end }}
{{ else }}
{{ warnf "<img/> render hook: %q not found" $path }}
{{ end }}
<img
src="{{ .Destination | safeURL }}"
alt="{{ .Text }}"
loading="lazy"
{{ if ne $width 0 }}width="{{ $width }}"{{ end }}
{{ if ne $height 0 }}height="{{ $height }}"{{ end }}
{{ with .Title}}title="{{ . }}"{{ end }}
/> Also, paths with a leading ./ won't resolve correctly. I've had to remove ./ from all my image paths, e.g. use |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
I have the same problem on v0.80.0/extended linux/amd64. Using the following code I get the full path of the file: {{ with imageConfig .imageUrl }}
{{ .Width }} x {{ .Height }}
{{ end }} |
I can still confirm the issue. I've got a PR open with that, freshly updated, with code that prints warning messages with image paths. It's still the same issue as the comments above, but here's the repo and PR if it can help with testing: GDQuest/website#233 Static images are mounted as assets/img to make them accessible as resources (iirc). [[module.mounts]]
source = "static/img"
target = "assets/img" And the output of
|
I am not convinced that there is a problem, though there may be room for improvements to the documentation. The The This content:
With this this template code:
Produces this output:
In the original description of this issue, @tyler71 passes a resourceAdapter instead of a path to When working with images as global resources ( |
That'd be definitely nice to have in the docs, and perhaps in errors too. If the problem is a matter of passing the wrong argument type, the error currently doesn't mention that, and we don't have type info in the templating language. I'll test code changes later, thanks! I've been unable to get this to work, and other people had the same issue on the discourse community. It'd be great if the fix could be so simple! |
1) If you would like to see changes to the documentation, create issues (or preferably pull requests) here: https://github.com/gohugoio/hugoDocs. 2) If you feel that the |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What version of Hugo are you using (
hugo version
)?I'm trying to get the width / height of a image
In the code below,
$img
outputsfiles/stats/img/my_image.png
The file is located at
When calling imageConfig, it shows this error:
Note the missing mydomain/assets/files
The text was updated successfully, but these errors were encountered: