I've been trying to adapt this helpful post to work with Image Transforms, so that the starting point for generating the responsive images is a cropped high resolution original.
I've defined a Transform called 'fullWidth' in the CMS, and have tried calling:
{% do image.setTransform('fullWidth') %}
Tearing my hair out, would someone be kind enough to assist?
Original code:
{% macro srcset(image, maxCssWidth, includeDimensions) %}
{%- spaceless %}
{# Is this a 2X image? #}
{% set is2x = image.filename matches '/@2x\\.\\w+$/' %}
{# Determine the CSS width for the image, if it were output at 100% #}
{% set cssWidth = (is2x ? round(image.width / 2) : image.width) %}
{# Determine the image size that 1X screens should get #}
{% set width = (cssWidth > maxCssWidth ? maxCssWidth : cssWidth) %}
{# Determine the image size that 2X screens should get #}
{% set width2x = (width * 2) > image.width ? image.width : (width * 2) %}
{# Output the srcset= attribute value #}
srcset="{{ image.getUrl(image.width != width ? { width: width }) }}, {{ image.getUrl(image.width != width2x ? { width: width2x }) }} 2x"
{#- Output the width= and height= attributes if needed #}
{%- if includeDimensions %} width="{{ width }}" height="{{ image.getHeight({ width: width }) }}"{% endif %}
{% endspaceless -%}
{% endmacro %}
srcset="{{ image.getUrl(image.width != width ? { width: width, mode : 'crop' }) }}, {{ image.getUrl(image.width != width2x ? { width: width2x, mode : 'crop' }) }} 2x"