# Nil pointer evaluating resource.Resource.Resize problem

**URL:** <https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529>\
**Category:** support\
**Created:** [May 14, 2020, 6:30pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529 "2020-05-14T18:30:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ourmaninindia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ourmaninindia/32/11036_2.png) [@ourmaninindia](https://discourse.gohugo.io/u/ourmaninindia)\
**Post date:** [May 14, 2020, 6:30pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529/1 "2020-05-14T18:30:19Z")

</div>

Laura Kalbag’s image formatting looks so easy but I fail to see why it does not work for me even though I use page bundles. It fails at $src.Resize  
If I remove the resize line it displays the image properly.

{{\< img src=“alfred-with-award.jpg” alt=“Alfred Tuinman with the award”\>}}

{{ $src := .Page.Resources.GetMatch (printf “_%s_” (.Get “src”)) }}  
{{ $tinyw := default “500x” }}  
{{ .Scratch.Set “tiny” ($src.Resize $tinyw) }}

Hugo v0.68.3  
Ubuntu 20.04

> **[ourmaninindia/summertimegoa](https://github.com/ourmaninindia/summertimegoa)**
>
> Contribute to ourmaninindia/summertimegoa development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 14, 2020, 7:10pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529/2 "2020-05-14T19:10:06Z")

</div>

I suspect that you have some pages that does not get a match.

Try

```auto
{{ $src := .Page.Resources.GetMatch (printf “%s” (.Get “src”)) }}
{{ if $src }}
{{ $tinyw := default “500x” }}
{{ .Scratch.Set “tiny” ($src.Resize $tinyw) }}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![ourmaninindia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ourmaninindia/32/11036_2.png) [@ourmaninindia](https://discourse.gohugo.io/u/ourmaninindia)\
**Post date:** [May 14, 2020, 7:17pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529/3 "2020-05-14T19:17:47Z")

</div>

src is just the file name but the system wants the .Permalink prefixed it seems so that the path is complete?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 14, 2020, 7:23pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529/4 "2020-05-14T19:23:33Z")

</div>

I gave you a piece of qualified advice, I suggest you try it before you reject it.

---

<div class="post-metadata">

**Author:** ![ourmaninindia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ourmaninindia/32/11036_2.png) [@ourmaninindia](https://discourse.gohugo.io/u/ourmaninindia)\
**Post date:** [May 14, 2020, 7:56pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529/5 "2020-05-14T19:56:23Z")

</div>

your piece of advise worked though I don’t understand why the {{ if $src }} makes it work as it is not as if $src changed. Anyway, I am delighted after wasting a few hours reading and trying. Pfff

The resized image is generated in resources as explained in the docs.

---

<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:** [May 16, 2020, 7:56pm UTC](https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-problem/25529/6 "2020-05-16T19:56:27Z")

</div>

Closed on May 16, 2020, 7:56pm UTC

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