-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_utilities.twig
28 lines (25 loc) · 989 Bytes
/
_utilities.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{% macro retina_crop(image, target_w, target_h) %}
{% spaceless %}
{%- if image -%}
{% set w = imageinfo(image).width %}
{% set h = imageinfo(image).height %}
{% set target_aspect = target_w / target_h %}
{% set w_n = min(target_w,min(h*target_aspect,w)) %}
{% set h_n = min(target_h,min(w/target_aspect,h)) %}
{% set w_n2x = min(target_w*2,min(h*target_aspect,w)) %}
{% set h_n2x = min(target_h*2,min(w/target_aspect,h)) %}
{% set retina = w_n2x > w_n %}
{% set default_retina = w_n2x == target_w*2 %}
{%- if retina -%}
{%- if not default_retina -%}
{{ "data-at2x='#{ image | thumbnail(w_n2x, h_n2x) }'"|raw }}
{%- endif -%}
{%- else -%}
{{ "data-no-retina='1'"|raw }}
{%- endif -%}
{{ " src='#{ image | thumbnail(w_n, h_n) }' width='#{target_w}' height='#{target_h}'"|raw }}
{%- else -%}
{{ " src='#{ image | thumbnail(target_w, target_H) }' width='#{target_w}' height='#{target_h}'"|raw }}
{%- endif -%}
{% endspaceless %}
{% endmacro %}