Open ismay opened 1 year ago
In thinking about this I suppose there are several ways to tackle this. The basics are that:
That could be added as an all in one method (e.g. image_base64_encode
). But since the base64_encode
filter already exists, just the loading of the image data could be sufficient (e.g. add image loading to load_data
). Whichever makes more sense from zola's perspective. Either would work I suppose.
Are you interested in working on this? I was going to automate this for myself but having blurry image placeholders in Zola would be pretty cool.
I don't have the time tbh. I moved to hugo, which already supports this:
{{ with .Resources.GetMatch "img.png" }}
<img src="data:{{ .MediaType.Type }};base64,{{ .Content | base64Encode }}">
{{ end }}
We would need to add a function to Zola to load the binary data of an image (load_data assumes utf-8) and we already have b64_encode as function
I'm looking at implementing low-quality image placeholders (LQIP) with zola. The one feature missing from zola to implement this is allowing the user to base64 encode an image from disk, in a template.
LQIP are a nice way to show users a blurred preview of the image that will load. Plus it prevents layout shift as images load, which is jarring for the user. See here for more details:
Basically the idea is:
The way I could see this working in zola is:
with the following css:
Just adding the loading of an image and subsequent base64 encoding of the image data would allow this to work, everything else already works with zola.