<style>
  {%- if image.height <= height %}
    {% assign maximum_height = image.height %}
  {% else %}
    {% assign maximum_height = height %}
  {% endif -%}

  {%- assign maximum_width = maximum_height | times: image.aspect_ratio -%}

  #{{ img_id }} {
    max-width: {{ maximum_width }}px;
    max-height: {{ maximum_height }}px;
  }

  #{{ wrapper_id }} {
    max-width: {{ maximum_width }}px;
  }
</style>
