Skip to content

Instantly share code, notes, and snippets.

@piotrpog
Created September 30, 2019 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotrpog/8bbc8714bdebb4d615ed9a68137dde4a to your computer and use it in GitHub Desktop.
Save piotrpog/8bbc8714bdebb4d615ed9a68137dde4a to your computer and use it in GitHub Desktop.
{# 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