Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize image in Hugo (v 0.32.x) in markdown

Tags:

hugo

I am trying to resize an image in Hugo (not using HTML / CSS), which is apparently available in the v 0.32 update. Beneath the "Image Processing" heading at the link in the last sentence, the following "Resize" method is described:

Resize to the given dimension, {{ $logo.Resize "200x" }} will resize to 200 pixels wide and preserve the aspect ratio. Use {{ $logo.Resize "200x100" }} to control both height and width.

I'm having some trouble implementing this in my Hugo site. In particular, I am using a .md file, and am trying to add an image which is stored somewhere else in the site's source files.

For example, here's how I would add the (not-resized) image in the .md file:

![pdf image](../static/_media/images/pdf.png)

How could I add this same file, resized to 50x50 pixels, using the resize method in the v0.32 release?

like image 719
Joshua Rosenberg Avatar asked Jan 02 '18 14:01

Joshua Rosenberg


1 Answers

Using my newer version of Hugo (v0.53) I had to adapt the answer by JoostS a bit:

  1. Created a page bundle
  2. Modified the shortcode to look like this at the start:

    
    {{ $original := .Page.Resources.GetMatch (print "images/" (.Get 0) "*") }}
    
like image 73
Jesper T Avatar answered Sep 28 '22 01:09

Jesper T