Ad

Using A Variable For Size Of Image In Img_url In Liquid

- 1 answer

I am trying to display an image in my shopify store with an aspect ratio of 4:1, but because I cannot know to image's size I am using the following code:

{% assign h = image_object.width | divided_by: 4 %}
{% assign size = image_object.width | append: "x" | append: h | strip %}
<img src="{{ image_object | img_url: size ,crop: 'center'}}">

but this doesn't work. The image stays in its original size.

Ad

Answer

The problem was that divided_by was returning a non-integer number which doesn't work with img_url. adding | floor solved the problem.

Ad
source: stackoverflow.com
Ad