Hi, I created shortcodes to resize images and used them for a while. I put asserts in the same directory as the .md file inside the “content” directory, and use this shortcode instead of the markup syntax because I want to format the appearance of the images. I pass a filename of a local asset to the shortcode. Then the shortcode does something similar to:
<img src = “{{ receivedurl” }}>
I noticed that the images are too big, and I want to resize them. I am trying different combinations on this code, but nothing works
{% set image1 = resize_image(path=receivedurl, height=250, format=“webp”) %}
<img src = “{{ image” }}>
Can somebody help me, please?
I believe you may be missing a “width
” parameter or an “op
” parameter depending on what you wish to accomplish.
You possibly wish to set a “width
” or use “op = "fit_height"
”
Ref: Image processing | Zola
So basically, the problem is that resize_image
cannot find your image because it’s not getting the full path.
The solution (that doesn’t involve manually writing in the full path into the shortcode) is to do something like this in the shorcode:
{% set document = page | default(value=section) -%} {# this ensures the shortcode works in both pages and sections -#}
{% set image1 = resize_image(path=document.colocated_path ~ receivedurl, height=250, format="webp") -%}
Essentially, page.colocated_path
or section.colocated_path
contain the path to where the colocated assets are for the page you’re currently processing, and you need to prepend the receivedurl
with that path.