Image processing

I think the imgproc shortcode in the docs 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:

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

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

{{ $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:

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

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

4 Likes