# Resize image given an url from partial

**URL:** <https://discourse.gohugo.io/t/resize-image-given-an-url-from-partial/21475>\
**Category:** support\
**Created:** [October 28, 2019, 12:44pm UTC](https://discourse.gohugo.io/t/resize-image-given-an-url-from-partial/21475 "2019-10-28T12:44:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![javifm86](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@javifm86](https://discourse.gohugo.io/u/javifm86)\
**Post date:** [October 28, 2019, 12:44pm UTC](https://discourse.gohugo.io/t/resize-image-given-an-url-from-partial/21475/1 "2019-10-28T12:44:11Z")

</div>

Hi,

I want to implement last articles on mi blog index.html with and image, and I have in front matter for each post a param:

> img: img/test.png

I can show the image with this code:

```
{{ with .Site.GetPage "/blog" }}
    {{ range first 4 .Pages }}
    <div>
        {{ $urlImg:= "" }}
        {{ $permalink := .Permalink }}
        {{ with .Params.img }}
        {{ $urlImg = (printf "%s%s" $permalink .) }}
        {{ end }}
        <a href="{{.Permalink}}">
            <img src="{{$urlImg}}">
            <span>{{.Title}}</span>
        </a>
    </div>
{{ end }}

```

I have tried with this partial:

`{{ partial "img.html" (dict "context" . "src" $urlImg ) }}`

And trying to show the width of the image in the partial, but it doesn´t work.

```
{{ $src := .context.Page.Resources.GetMatch (printf "*%s*" .src) }}
{{ $src.Width }}

```

Any help please? I am new in Hugo. I have a shortcode for responsive images, but I can´t get the same in a partial.

Thanks a lot, best regards.

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [October 28, 2019, 1:15pm UTC](https://discourse.gohugo.io/t/resize-image-given-an-url-from-partial/21475/2 "2019-10-28T13:15:25Z")

</div>

Hi,

I’m just guessing here, but I think your issue is with the path you are passing to `.GetMatch`. It looks like you are passing the full rendered URL of the img, ie `yoursite.com/blog/foo/bar.png`, which works for the img `src` attribute.

However `.GetMatch`, as a [Page Resources](https://gohugo.io/content-management/page-resources/) method, is relative to the `.Page` object.

See [this example in the docs](https://gohugo.io/content-management/page-resources/#pattern-matching). If you have a [Page Bundle](https://gohugo.io/content-management/page-bundles/) at `content/blog/foo/index.md` , the example image above would be located at `content/blog/foo/images/sunset.jpg`, in the specific example.

---

<div class="post-metadata">

**Author:** ![javifm86](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@javifm86](https://discourse.gohugo.io/u/javifm86)\
**Post date:** [October 29, 2019, 10:20am UTC](https://discourse.gohugo.io/t/resize-image-given-an-url-from-partial/21475/3 "2019-10-29T10:20:01Z")

</div>

Thanks for the links, I could correct it and make it work:

```
{{ with .Site.GetPage "/blog" }}
{{ range first 4 .Pages }}
<article>
    <a class="hover:text-green-500" href="{{.Permalink}}">
        {{ $contextBlog := . }}
        {{ with .Params.img }}
            {{ $resources := $contextBlog.Resources.Match . }}
            {{ $cover := index ($resources) 0 }}
            {{ with $cover.Width }}
                {{ $img := $cover }}
                {{ if ge $cover.Width "640" }}
                    {{ $img = $cover.Resize "640x" }}
                {{ end }}
                {{ partial "img.html" (dict "context" . "img" $img) }}
            {{ end }}
        {{ end }}
        <span>{{.Title}}</span>
    </a>
</article>
{{ end }}
```
