{% macro resize_image(path, imgWidth, imgHeight, containerImgWidth, containerImgHeight, extendClass) %}
{% set extendClass = extendClass|default("") %}
{% set width = imgWidth %}
{% set height = imgHeight %}
{% if imgWidth > containerImgWidth %}
{% set width = containerImgWidth %}
{% set height = imgHeight*width/imgWidth %}
{% if height > containerImgHeight %}
{% set height = containerImgHeight %}
{% set width = imgWidth*height/imgHeight %}
{% endif %}
{% elseif imgHeight > containerImgHeight %}
{% set height = containerImgHeight %}
{% set width = imgWidth*height/imgHeight %}
{% if width > containerImgWidth %}
{% set width = containerImgWidth %}
{% set height = imgHeight*width/imgWidth %}
{% endif %}
{% endif %}
{% set marginTop = (containerImgHeight - height)/2 %}
{% set marginLeft = (containerImgWidth - width)/2 %}
{% set imgStyle %}
{% spaceless %}
margin: {{ marginTop|round|abs }}px {{ marginLeft|round|abs }}px
{% endspaceless %}
{% endset %}
{% endmacro %}
{% macro fillResize(path, imgWidth, imgHeight, containerImgWidth, containerImgHeight, extendClass) %}
{% set extendClass = extendClass|default("") %}
{% set width = imgWidth %}
{% set height = imgHeight %}
{% if imgWidth > imgHeight %}
{% set height = containerImgHeight %}
{% set width = imgWidth/(imgHeight/containerImgHeight) %}
{% if width < containerImgWidth %}
{% set height = height*containerImgWidth/width %}
{% set width = containerImgWidth %}
{% endif %}
{% else %}
{% set width = containerImgWidth %}
{% set height = imgHeight/(imgWidth/containerImgWidth) %}
{% endif %}
{% set marginTop = (containerImgHeight - height)/2 %}
{% set marginLeft = (containerImgWidth - width)/2 %}
{% set imgStyle %}
{% spaceless %}
margin: {{ marginTop|round }}px {{ marginLeft|round }}px
{% endspaceless %}
{% endset %}
{% endmacro %}