grav
grav copied to clipboard
Modified image gets reset after `html()` in twig template; `width` and `height` not correct
Environment
Grav: v1.7.31 Admin: v1.10.31
auto_sizes
is enabled.
Example
Twig template
{# test 1 #}
{% set img1 = image.cropResize(1200,1200) %}
{{ img1.path() }} {# path to cropResize image #}
{{ img1.path() }} {# suddenly reset to original image #}
{# test 2 #}
{% set img1 = image.cropResize(1200,1200) %}
{{ img1.get('width')|raw }} {# original width not expected cropResize #}
{{ img1.get('height')|raw }} {# original height not expected cropResize, but not resets the image #}
{{ img1.html()|raw }} {# outputs correct width and height #}
{{ img1.html()|raw }} {# suddenly reset to original image #}
{# test 3 #}
{% set img1 = image.cropResize(1200,1200) %}
{{ img1.get('width')|raw }} {# original width not cropResize #}
{{ img1.get('height')|raw }} {# original height not cropResize #}
{{ img1.path()|getimagesize[0] }} {# correct width #}
{{ img1.path()|getimagesize[1] }} {# resets to original like test 1 #}
{# test 4 #}
{{ image.cropResize(1200,1200).html()|raw }}
{{ image.cropResize(1200,1200).html()|raw }} {# correct file, not reset like in test 1 #}
Output
{# test 1 #}
/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg
/images/5/e/4/4/1/5e44127351cd4a12f9aaeb4691c964e272f76321.jpeg
{# test 2 #}
2736
1824
<img alt="" src="/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg" width="1200" height="800" />
<img alt="" src="/images/5/e/4/4/1/5e44127351cd4a12f9aaeb4691c964e272f76321.jpeg" width="2736" height="1824" />
{# test 3 #}
2736
1824
1200
1824
{# test 4 #}
<img alt="" src="/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg" width="1200" height="800" />
<img alt="" src="/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg" width="1200" height="800" />
Expected behavour
- Output should not change if
html()
is called twice like in test 2. - Output should be consistent like test 4.
- Furthermore the
width
andheight
should be from the modified image and not the original image.
Related issues
- Seems similar but just an
enhancement
? #1058 - This issue could be the reason for my srcset issue #2307
- Maybe also related #2342 and #2348
Actually, html()
and some other methods reset the image "by purpose". Also, the size of the image only changes only when the operations get applied. So the results are what I am expecting due to limitations in the implementation.
That said, I'm currently rewriting all of this logic for Grav 1.8; the size is now being calculated per operation, but I have not yet touched the reset behavior as I think it's being used in somewhere.