/
img_url

img_url

Creates a thumbnail for an image attachment and returns it’s url. You can pass a width parameter and extra arguments with the img_url filter to define what thumbnail you want. The first parameter is the width.

Input:

{{ attachment | img_url: 300 }}

Output:

https://plate-assets.com/img/12ab34cd56/my-image.jpg?width=300

If you only pass the one argument (width) the aspect ratio is maintained. You can add the height argument to force dimensions, but also arguments like blur and dpr to create a thumbnail of the image to your liking.

Input:

{{ attachment | img_url: 300, height: 200, mode: "stretch", blur: 5 }}

Output:

Note: img_url only works on an attachment or the attachment src (attachment.src). Also GIF files do not work.

Image Cropper:

  • For attachment input: img_url displays the cropped version in the admin editor. Note that the crop option will override existing cropped version.

  • For attachment src input, img_url will not automatically display the cropped version. It's recommended to include crop: attachment.crop along with the src input.

Below you can find all arguments you can use on the img_url and what they do.

width

Specifies the width of the output image in pixels.

If the width is set to 0 its value will be automatically calculated based on the supplied height value, so that the original image aspect ratio is preserved. If both width and height are supplied, the image will be resized according to the mode setting.

height

Specifies the height of the output image in pixels.

If the height is omitted or set to 0 (default) its value will be automatically calculated based on the supplied width value, so that the original image aspect ratio is preserved. If both width and height are supplied, the image will be resized according to the mode setting.

mode

Controls the resize mode when both a width and height are specified.

Available modes:

  • fit: Resize to fit within the boundaries defined by the width and height parameters, while maintaining the original aspect ratio. If the output aspect ratio differs from the original, only one of the dimensions (width or height) will equal its set value, while the other will be smaller.

  • crop: Resize to fill the entire area defined by width and height, by maintaining the aspect ratio, but possibly clipping part of the image.

  • stretch: Resize to fill the entire area defined by width and height, by modifying the aspect ratio.

The default mode is fit.

 

mode: "fit"

 

mode: "crop"