Created
February 23, 2018 05:44
-
-
Save umkasanki/4bd30faec719974cc069c12ffc1bc71e to your computer and use it in GitHub Desktop.
Предварительная нарезка и сжатие изображений с сохранением путей в json.
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
{% spaceless %} | |
{% set srcsets = [] %} | |
{% for image in entry.images %} | |
{% set imgSize = max(image.width, image.height) %} | |
{% set transformedImages = craft.imager.transformImage(image, [ | |
{ width: imgSize >= 1200 ? 1200 : imgSize, jpegQuality: 90 }, | |
{ width: imgSize >= 1000 ? 1000 : imgSize, jpegQuality: 90 }, | |
{ width: 600 }, | |
{ width: 300, jpegQuality: 65 }, | |
{ width: 100, jpegQuality: 65 } | |
], { | |
format: 'jpg', | |
ratio: 1/1, | |
position: 'center-center', | |
mode: 'letterbox', | |
auto: 'format,compress' | |
}) %} | |
{% set arr = { | |
maxSize: imgSize, | |
w1200: transformedImages[0].url, | |
w1000: transformedImages[1].url, | |
w600: transformedImages[2].url, | |
w300: transformedImages[3].url, | |
w100: transformedImages[4].url | |
} %} | |
{% set srcsets = srcsets|merge([arr]) %} | |
{% endfor %} | |
{{ srcsets|json_encode() }} | |
{% endspaceless %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment