Closed douglas-johnson closed 1 month ago
I am rewriting this issue for the Shopify Blocks instead of the products block, but the idea is the same.
We currently only support the 1:1 square aspect ratio for images in the Shopify block. We commonly also have images in 3:2
landscape and 3:4
portrait aspect ratios.
Ideally, product photos are uploaded as large 3:2 images and are composed in such a way that 1:1, 2:1 and 3:4 crops still contain the subject.
Just like we would do with the WordPress VIP CDN, Shopify lets you adjust the dimensions of an image using the CDN URL. You can experimenrt with that here: https://cdn.shopify.com/
Currently, we set the width in the URL, and then assume the image will be a square when we add width and height to the <img>
tag.
We can obtain the width and height of the full size image from GraphQL like this:
{
products(first: 3) {
nodes {
title
featuredImage {
altText
width
height
url
}
}
}
}
Once we know the maximum dimenstions, we could provide them as a parameter along with the desired aspect ratio and an arrray of widths to produce <img>
tags.
We do this in the rest block. For example, we do it here for the 4:5 aspect ratio image we use in the middle of the trending layout.
Also, we do sort of the same calculation in JavaScript for the REST API block. I mean to link to that along with the server side rendered version. https://github.com/thoughtis/cata-blocks/blob/main/blocks/rest/src/components/image/get-dimensions.js
Background
On Shop Catalog we have an established pattern for feature images that should allow the vast majority of products to support portrait, landscape and square version of their feature image. The products block is all square because of the way we designed it for Creepy Catalog where it has a film strip frame around it.
We recently added the reel style and the square images make the final output a little larger than necessary. If we were able to use the portrait crop, the resulting image would contain more of the product, especially in the case of books.
That could mean we can fit more products on the page horizontally in the reel layout.
Details