Created
September 30, 2019 00:08
-
-
Save piotrpog/8bbc8714bdebb4d615ed9a68137dde4a to your computer and use it in GitHub Desktop.
Generates favicon from static file using Imager. More info: http://craftsnippets.com/articles/adding-favicons-to-craft-cms-website#generating-favicon-from-static-image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# 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