Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{# v1 #}
{# settings #}
{% set faviconFileName = '/static/images/favicon.jpg' %}
{% set sizesIcon = [192, 48, 32, 16] %}
{% set sizesAppleTouch = [180] %}
{# output #}
{% if craft.app.plugins.isPluginEnabled('imager') and craft.imager.transformImage(faviconFileName, {}, null, {suppressExceptions : true}) %}
{% for faviconSize in sizesIcon %}
{% set faviconTransform = {
width: faviconSize,
height: faviconSize,
quality: 100,
position: 'center-center',
format: 'png',
} %}
{{tag('link', {
rel: 'icon',
sizes: faviconSize ~ 'x' ~ faviconSize,
type: 'image/png',
href: craft.imager.transformImage(faviconFileName, faviconTransform, null, {suppressExceptions : true}),
})}}
{% endfor %}
{# link touch icon #}
{% for faviconSize in sizesAppleTouch %}
{% set faviconTransform = {
width: faviconSize,
height: faviconSize,
quality: 100,
position: 'center-center',
format: 'png',
} %}
{{tag('link', {
rel: 'apple-touch-icon',
sizes: faviconSize ~ 'x' ~ faviconSize,
href: craft.imager.transformImage(faviconFileName, faviconTransform, null, {suppressExceptions : true}),
})}}
{% endfor %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.