Do you have your site code somewhere we can have a look at? It’s generally easier to help if we can replicate the error you are getting. Have a read here about Requesting Help .
I suspect what you see here is concurrency in play, i.e. the error message you see is not connected to the image you think is there.
I think you can make your code more robust by doing:
{{ if .image }}
{{ with $currentPage.Resources.GetMatch .image }}
{{ printf "%#v" .MediaType }} <!-- Works -->
{{ printf "%#v" .Permalink }} <!-- Works -->
{{ printf "%#v" (.Resize "180x") }} <!-- Does not work -->
{{ end }}
{{ end }}
I am having a very similar error to this and can’t see how to get this to work.
Here is the code in my list.html default:
{{- if isset .Params "thumbnail" -}}
{{- $imagePath := (printf "*%s*" .Params.thumbnail) -}}
{{ with .Resources.GetMatch $imagePath }}
{{ if eq .ResourceType "image"}}
{{ $image := . }}
{{ $image.Resize "600x" }}
{{ end }}
{{ end }}
<img src="{{ .Permalink }}/{{ .Params.thumbnail }}" alt="">
{{ end }}
And I get an error:
: execute of template failed: template: _default/list.html:18:21: executing "main" at <$image.Resize>: error calling Resize: *resources.genericResource is not an image
{{ if eq .ResourceType "image"}}
{{ $image := . }}
{{ $image.Resize "600x" }}
{{ end }}
{{ end }}
hugo v0.92.0+extended darwin/amd64 BuildDate=unknown
Am I not checking the type correctly? How can it pass the if statement for ResourceType and then claim the resource not an image?
The img tag (which is a hold over from before I wanted to start image processing) works fine with the path provided.
So as is often the case when I get around to posting to a forum, I found the main problem. Out of about 20 images, one was an svg. I took it out for now but now I am wondering if there is an effective way to check if an image is an svg before processing.