Little trick I’m posting for my future self.
To make responsive images with Hugo, simply use the image filters, then pimp it up with CSS.
My version has a category and section, so my image path looks like:
RESPONSIVE IMAGES (kind of)
We have large (1700x900 or something) images everywhere on the website. No need to download those on mobile phones. We need the scaled version, right?
IMAGES:
Desktop: 1700x900 x 100% quality on jpg
Mobile: 500x270 x 75% quality on jpg
(note: a huge bee tried to sting me just now, I had to go full caveman on a fight to the death situation here. Adrenaline pumping through my veins. I’m the man.)
Now, here’s what my image path looks like. Depending on your project, yours may vary.
On my .MD file:
featured_image: "die_bee.jpg"
That’s it, no path, no anything. I just call the filename and its extension.
I save the image here:
http://localhost:1313/news/universe/img/this_is_my_img.jpg
Here’s the magic:
some_template.htmml
{{ $cat := .Params.categories | anchorize }}
{{ $base := print .Section "/" $cat "/img" }}
{{ $path := print .Params.featured_image }}
{{ $url := print $base "/" $path }}
{{ $image := resources.Get $url }}
{{ $scaled := $image.Fill "500x270 center q75" }}
<img src="{{ $image.Permalink }}" class="d-none d-sm-block"> <-- mobile= off, desktop= on-->
<img src="{{ $scaled.Permalink }}" class="d-block d-sm-none"> <-- mobile= on, desktop= off -->
That’s it. The CSS is simple enough. I use Bootstrap to hide and show divs.
If you don’t use bootstrap and have no idea how media queries work, try something like this.