Skip to content

Instantly share code, notes, and snippets.

@umkasanki
Created February 23, 2018 05:44
Show Gist options
  • Save umkasanki/4bd30faec719974cc069c12ffc1bc71e to your computer and use it in GitHub Desktop.
Save umkasanki/4bd30faec719974cc069c12ffc1bc71e to your computer and use it in GitHub Desktop.
Предварительная нарезка и сжатие изображений с сохранением путей в json.
{% 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