The image object

An image object returns information about an image. Image objects are usually attributes of other objects, such as product, variant, collection, and article.

The image object has the following attributes:

image.alt

Returns the alt tag of the image, set in the Products page of the Admin.

image.aspect_ratio

Returns the aspect ratio (width / height) of the image.

image.attached_to_variant?

Returns true if the image has been associated with a variant. Returns false otherwise. This can be used in cases where you want to create a gallery of images that are not associated with variants.

image.height

Returns the height of the image in pixels.

image.id

Returns the ID of the image.

image.media_type

Returns the type of the object (image).

The media_type property can be used to filter the product.media array for all media of a desired type.

image.position

Returns the position of the image in the product object's media array.

image.preview_image

Returns a preview image for the image.

image.product_id

Returns the id of the image's product.

image.src

Returns the relative path of the product image. This is the same as outputting {{ image }}.

To return the URL of the image on Shopify's Content Delivery Network (CDN), use the appropriate URL filter.

To see a full list of available image sizes, see image size parameters.

Shown below is an example of loading a product image using the image_url filter.

image.variants

Returns an array of attributes for the variant that the image is associated with.

image.width

Returns the width of the image in pixels.