{# Set Attributes {% set options = { class: 'm-figure', sizes: [ { width: 1680 }, { width: 960 }, { width: 480 } ], background: false, elementtype: 'figure', quality: 80, mode: 'crop', position: '50% 50%', ratio: IMAGE_ELEMENT_RATIO, caption: IMAGE_ELEMENT_CAPTION, captionTitle: IMAGE_ELEMENT_CAPTION_TITLE, captionSource: IMAGE_ELEMENT_CAPTION_SOURCE, captionSourceUrl: IMAGE_ELEMENT_CAPTION_URL, dominantColor: true, effects: { grayscale: true }, } %} macroResImage.resImage(image, options) #} {% macro resImage(image,options) %} {# Set Defaults #} {% set defaults = { class: 'm-figure', sizes: [ { width: 1400 }, { width: 1100 }, { width: 800 }, { width: 500 }, { width: 300 }, { width: 30 } ], background: false, elementtype: 'figure', quality: 80, mode: 'crop', position: false, ratio: false, caption: false, captionTitle: false, captionSource: false, captionSourceUrl: false, dominantColor: false, effects: {}, } %} {# Merge Attr with Defaults #} {% set options = options is defined ? defaults|merge(options) : defaults %} {% if image %} {# Set Ratio #} {% if options.ratio %} {% set ratio = options.ratio|split(':') %} {% set base64Ratio = options.ratio|split(':') %} {% set ratio = ratio|first/ratio|last %} {% else %} {% set imageSize = image.width ~ ':' ~ image.height %} {% set base64Ratio = imageSize|split(':') %} {% set ratio = '' %} {% endif %} {# Set Position #} {% if options.position %} {% set position = options.position %} {% elseif image.settingsFocalPoint %} {% set position = image.settingsFocalPoint %} {% else %} {% set position = '50% 50%' %} {% endif %} {# Define global variables #} {% set imageSettings = { jpegQuality: options.quality, mode: options.mode, position: position, ratio: ratio, effects: options.effects } %} {# Image #} {% set images = craft.imager.transformImage(image, options.sizes, imageSettings) %} {# Set Dominant Color #} {% if options.dominantColor %} {% set dominantColor = craft.imager.getDominantColor(images|last, 20) %} {% else %} {% set dominantColor = '' %} {% endif %} {% if options.background %}
{% else %}