# Image processing

**URL:** <https://discourse.gohugo.io/t/image-processing/15501>\
**Category:** support\
**Created:** [November 26, 2018, 6:28pm UTC](https://discourse.gohugo.io/t/image-processing/15501 "2018-11-26T18:28:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wobl42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wobl42/32/7403_2.png) [@wobl42](https://discourse.gohugo.io/u/wobl42)\
**Post date:** [November 26, 2018, 6:28pm UTC](https://discourse.gohugo.io/t/image-processing/15501/1 "2018-11-26T18:28:52Z")

</div>

Hi,  
where can I find a working example on how to resize images?  
Documentation ([https://gohugo.io/content-management/image-processing/](https://gohugo.io/content-management/image-processing/)) doesn’t help me because I don’t know how to use it.

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [November 26, 2018, 6:53pm UTC](https://discourse.gohugo.io/t/image-processing/15501/2 "2018-11-26T18:53:08Z")

</div>

Sample 🙂

```
{{ define "main" }}

< snipped >

<div>{{ .Content }}</div>
<hr/>
<div>
{{range .Resources.Match "gallery/*" }}{{ $original := . }}
	{{ $.Scratch.Set "image" ($original.Fit "370x370") }}{{ $image := $.Scratch.Get "image" }}
	<a class="dim b--white" data-fancybox="gallery" href="{{.RelPermalink | relURL}}" >
		<img class="ba bw1 b--dark-blue" src="{{ $image.RelPermalink | relURL}}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{.Name}}" /> 
	</a>
{{ end }}
</div>
{{ end }} 

```

Use of CSS tachyons and [Fancybox](https://fancyapps.com/fancybox/3/) for the picture gallery.  
I store the pictures in sub-dir ./gallery, the thumb images are resized.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [November 26, 2018, 7:02pm UTC](https://discourse.gohugo.io/t/image-processing/15501/3 "2018-11-26T19:02:38Z")

</div>

I think the `imgproc` shortcode in the [docs](https://gohugo.io/content-management/image-processing/#image-processing-examples) is very helpful.

* * *

But, to add to @ju52’s sample, here is another.

Let’s say you have a blog post `some-post`, and your image is part of a [leaf bundle](https://gohugo.io/content-management/page-bundles/):

```auto
├── content
│ └── blog
│ └── some-post
│ ├── index.md
│ └── space.jpg

```

You could define a shortcode, `layouts/shortcodes/img-resize.html`:

```auto
{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get "img")) }}
{{ $new := $original.Resize (.Get "size") }}
<a href="{{ $original.Permalink }}"><img src="{{ $new.Permalink }}"></a>

```

Then use it in your post like:

```auto
{{< img-resize img="space.jpg" size="500x300" >}}

```

This simple shortcode resizes an image, then gives a link to the original.

---

<div class="post-metadata">

**Author:** ![wobl42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wobl42/32/7403_2.png) [@wobl42](https://discourse.gohugo.io/u/wobl42)\
**Post date:** [November 26, 2018, 8:04pm UTC](https://discourse.gohugo.io/t/image-processing/15501/4 "2018-11-26T20:04:07Z")

</div>

> [@zwbetz](#):
>
> {{ $original := .Page.Resources.GetMatch (printf “_%s_” (.Get “img”)) }} {{ $new := $original.Resize (.Get “size”) }} \<a href=“{{ $original.Permalink }}”\>\<img src=“{{ $new.Permalink }}”\>\</a\>

Thanks a lot - this was really helpful for me 🙂
