# Get image size from .Page.Resource

**URL:** <https://discourse.gohugo.io/t/get-image-size-from-page-resource/10666>\
**Category:** support\
**Created:** [February 21, 2018, 5:40pm UTC](https://discourse.gohugo.io/t/get-image-size-from-page-resource/10666 "2018-02-21T17:40:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunoamaral](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brunoamaral/32/21144_2.png) [@brunoamaral](https://discourse.gohugo.io/u/brunoamaral)\
**Post date:** [February 21, 2018, 5:40pm UTC](https://discourse.gohugo.io/t/get-image-size-from-page-resource/10666/1 "2018-02-21T17:40:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![brunoamaral](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brunoamaral/32/21144_2.png) [@brunoamaral](https://discourse.gohugo.io/u/brunoamaral)\
**Post date:** [February 21, 2018, 5:54pm UTC](https://discourse.gohugo.io/t/get-image-size-from-page-resource/10666/2 "2018-02-21T17:54:10Z")

</div>

Nevermind, found the answer 🙂

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

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [April 22, 2021, 8:46pm UTC](https://discourse.gohugo.io/t/get-image-size-from-page-resource/10666/3 "2021-04-22T20:46:29Z")

</div>

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