Get image size from .Page.Resource

I was thinking about building a shortcode that would produce a gallery from the indication of a folder. Something like this:

 {{ $galleryimages := .Page.Resources.Match "gallery-*" }}
 
 {{ range $galleryimages }}
 {{ $thumbnail := .Resize "320x" }}
 
 		<figure itemscope itemtype="http://schema.org/ImageObject" class="image">
 		  <a href="{{ .Permalink }}" itemprop="contentUrl" data-size="--SIZE--" >
 		      <img src="{{ $thumbnail.Permalink }}" itemprop="thumbnail" alt="--caption--" />
 		  </a>
 
 		  <figcaption itemprop="caption description">
 		    --caption--
 		    <span itemprop="copyrightHolder">--copyrightHolder--</span>
 		  </figcaption>
 		</figure>
 
 {{ end }}

The only missing piece, is to be able to get the width and height of the image for the data-size attribute.

Is there a way to get this directly from the file?

Nevermind, found the answer :slight_smile:

<a href="{{ .Permalink }}" itemprop="contentUrl" data-size="{{ .Width }}x{{ .Height }}" >
5 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.