{% set size = size|default('thumb') %}
{% set classPicture = classPicture|default('') %}
{% set class = class|default('') %}
{% set alt = alt|default('') %}
{% set field = field|default('imageFile') %}
{% set query = query|default({
'x-large': '(min-width: 1500px)',
'large': '(min-width: 1200px) and (max-width: 1499)',
'medium': '(min-width: 768px) and (max-width: 1199px)',
'small': '(max-width: 767px)',
})%}
{% set object = object|default('') %}
{% if not object %}
{% if app.environment == 'dev' %}
Не передан объект для получения изображения!
{% endif %}
{% else %}
{% set configs = get_image_size_configs(size) %}
{% set image = vich_uploader_asset(object, field) %}
<picture class="{{ classPicture }}">
{% set firstConfig = null %}
{% for queryName, mediaQuery in query %}
{% set configItem = configs[queryName]|default(null) %}
{% if configItem and not firstConfig %}
{% set firstConfig = configItem %}
{% endif %}
{% set configItem2x = configs[queryName ~ '_2x']|default(null) %}
{% set configItemWebp = configs[queryName ~ '_webp']|default(null) %}
{% set configItemWebp2x = configs[queryName ~ '_webp_2x']|default(null) %}
{{ _self.pictureSource(image, configItemWebp, configItemWebp2x, mediaQuery, 'image/webp') }}
{{ _self.pictureSource(image, configItem, configItem2x, mediaQuery) }}
{% endfor %}
{# Привет, друг! Если ругается про filterSet и прочие странные шутки - почисти кеш :) #}
<img src="{{ image | imagine_filter(firstConfig.filter_set, firstConfig.filters) }}" alt="{{ alt }}" class="{{ class }}" loading="lazy"/>
</picture>
{% endif %}
{% macro pictureSource(image, config1x, config2x, mediaQuery, type) %}
{% if config1x and config2x %}
<source srcset="{{ image | imagine_filter(config1x.filter_set, config1x.filters) }} 1x,
{{ image | imagine_filter(config2x.filter_set, config2x.filters) }} 2x"
media="{{ mediaQuery }}"
{% if type %}type="image/webp"{% endif %}>
{% endif %}
{% endmacro %}