imageConfig with Page Bundles how to?

I want to add width="xxx" and height="xxx" in my figure.html.
So having Page Bundles, cannot find right way.

First attempt:

{{/* OK */}}
{{ $img1 := .Get "src"}} 
{{/* OK */}}
{{ $img2 := .Page.RelPermalink }} 
{{/* OK */}}
{{ $imgFile := path.Join "/" $img1  $img2 }}
{{/* OK */}}
{{ with imageConfig ( $imgFile) }}

Hugo add /img/ in the path and throw error.

domain-path \img \slug

Found code in forum with .Destination… but Hugo throw error.

Surprising, with this code no error:

{{ with imageConfig ( $imgFile ) }}
 {{ $width=  .Width }}
 {{$height =  .Height }}
    {{ end }}

But getting this code in <img tag:

{{ with imageConfig ( $imgFile ) }}
    width="{{ .Width }}"
    height="{{ .Height }}"
    {{ end }}

Hugo throw error because insert /img/ string in path.

update:

{{ $img2 := $.Page.Resources.GetMatch (.Get "src") }}
{{ with imageConfig ( $img2 ) }}
{{ end }}

throw error:

failed to render shortcode "figureh": failed to process shortcode: execute of template failed at <imageConfig ($img2)>: error calling imageConfig: config needs a filename 

A resource in a page what else is supposed to be other than a file?

So how to obtain image width and height suitable for figure shortcut?

Thanks.

A resource on a page is a Resource which is a Go interface with a set of methods (e.g. .RelPermalink). It’s not a file.

But, a image resource already has (most of) the imageConfig available so you can do:

{{ $img := $.Page.Resources.GetMatch "myimage.jpg" }}
{{ $img.Width }}

@bep

A resource on a page is a Resource which is a Go interface with a set of methods (e.g. .RelPermalink ). It’s not a file.

Very good point. Thank you.

But, a image resource already has (most of) the imageConfig available so you can do:

{{ $img := $.Page.Resources.GetMatch "myimage.jpg" }}
{{ $img.Width }}

Would have been nice, but:

{{$src := .Get "src"}}
{{ $img := $.Page.Resources.GetMatch $src }}
<h1>{{ $img.Width }}</h1>

failed to render shortcode "figureh": failed to process shortcode: 
...
execute of template failed at <$img.Width>: nil pointer evaluating resource.Resource.Width 

Trying to replace .webp image with .jpg, same result.
Trying also using existing file name like your example, with same result.

{{ $img := $.Page.Resources.GetMatch "annalena-berton-danza.jpg" }}

This print file name

<h1>{{ $img }}</h1>
<h1>{{ print $img }}</h1>

This throw error:

<h1>{{ $img.Width }}</h1>

update: reading Page Resources | Hugo also throw same error:

<h1>{{ $img.MediaType.MainType }}</h1>

maybe $src is not a string, or type expected by .Resource interface… but “annalena-berton-danza.jpg” surely is like examples in page.

Please provide a link to a public repository or a reproducible test case repository as per Requesting Help.
At a guess the .jpg is corrupted or not actually a jpeg.

@cshoredaniel Here is:

you can find string “PROBLEM DISCOURSE” in figureh.html. Page with problem is /danza-in-zona-loreto/

I tried now too but it gives same error. Thank you for your time.

at least, has an image that is in static/img instead of in a page bundle. static files cannot be used for page or site resources and will fail.

See Hugo Pipes Introduction | Hugo for site resources (you already found the link for page resources).

Remember that the figureh shortcode applies to all calls of figureh in all pages.