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:
Returns the alt tag of the image, set in the Products page of the Admin.
image.aspect_ratio
Anchor link to section titled "image.aspect_ratio"Returns the aspect ratio (width
/ height
) of the image.
image.attached_to_variant?
Anchor link to section titled "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
Anchor link to section titled "image.height"Returns the height of the image in pixels.
Returns the ID of the image.
image.media_type
Anchor link to section titled "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
Anchor link to section titled "image.position"Returns the position of the image in the product
object's media array.
image.preview_image
Anchor link to section titled "image.preview_image"Returns a preview image for the image.
image.product_id
Anchor link to section titled "image.product_id"Returns the id of the image's product.
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
Anchor link to section titled "image.variants"Returns an array of attributes for the variant that the image is associated with.
image.width
Anchor link to section titled "image.width"Returns the width of the image in pixels.